I have a situation where I need to download a list of large files, one at a time. My existing strategy is to use the completion callback of one download to begin the next, continuing until the list is empty.
In general, this works fine whether the app is in the foreground or background.
The problem arises when the server reports some error with handling the request while the app is in the background and the error is deemed recoverable (too busy, for example).
The behaviour I'd like is to delay a random value in the range of 0.5 to 3.0 minutes and then re-issue the request. However, I know that there's a very limited amount of time allowed before the app must return from the callback or it will be terminated. (10 seconds?) Additionally, this should happen without any user involvement because the most likely usecase is that the user queues up a list of downloads and walks away, or goes to sleep....
Returning from the callback without issuing another request means not getting an opportunity to process the rest of the list until the app is brought to the foreground again.
What I need is something that acts as if it were a resumeAfter: or suspendUntil: method on NSURLSessionTask.
Suggestions?