I am currently working on a POC app, I have previously posted about it here. I am trying to handle automatic refreshing of an authentication token should my server give me a 401
Assuming you can change implementation of requestAuth, add a completion handler parameter to requestAuth function.
Inside requestAuth implementation, call that handler after token is received. Then in requestDataForUser:
case 401:
NSLog(@"401 Challenge - Retrying Authentication, Attempt %ld", (long)retryAttempts);
[weakSelf refreshAuth withCompletionHandler:weakself.requestDataForUser];
retryAttempts += 1;
break;
Otherwise, use NSOperationQueue and set maximum concurrent operation to 1:
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 1;
[queue addOperationWithBlock:^{
[weakself requestAuth];
}];
[queue addOperationWithBlock:^{
[weakself requestDataForUser];
}];