Background
A user of my app does something with my app, that schedules asynchronous AFNetworking HTTP request with some completion handler.
Then, without a delay, user of my app goes to a home screen so my app enters to a background.
A network is very slow, so my app will receive response after 20 seconds, which means that network response will reach my app when it is in background state.
Questions
What will happen to this network request and specifically to its completion handler?
I know, that dispatch_async retains all the stuff passed to its block, so I expect a completion handler of my response to be executed at some point, is it so?
P.S.
I don't mean asynchronous HTTP requests intended to run when application is in background, I mean regular asynchronous HTTP requests that are performed when app is in normal state.
UPDATE 1
I did find a partial answer in the related topic: What happens to tasks in dispatch queues when an app enters inactive/background/suspended states in iOS?.
I'll quote it shortly:
When an app is suspended, the entire process is frozen... tasks existing in pre-suspension GCD queues do not disappear upon resumption. They never went away; they were only paused.
The most simple test I tried is the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
double delayInSeconds = 10.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSLog(@"I am alive!");
});
return YES;
}
If I launch this app, then go to background immediatedly, then wait enough (so 10s can pass), then activate it - I see how NSLog message appears in a console.
What I still don't understand is how this applied to delayed HTTP responses - if an app is frozen - how they are handled then? If someone is aware of how app's transition to background affects how it will handle delayed HTTP responses, please do share your knowledge!