I’m using a specific API, that requires refresh a token in order to use it.
Once you refresh this token it’s available for half an hour, and then becomes invalid. And then I have to refresh it again. What I’m doing now is to refresh it on every request, but they are happening fast, in the matter of seconds or minutes, so that’s probably not the best approach.
If you can advice me something it would be great!
You could always have some ivar or variable saved in an object that says the last time the token was refreshed, where when a request comes in, check the “
NSTimeInterval” between now and the date/time when that token was set and then submit a new token request if the time is greater than 30 minutes.The advantage of doing it this way (versus using a timer) would be that during long periods of inactivity, you’d request new 30 minute tokens as needed and not every 30 minutes the application is alive.