Note that there are some explanatory texts on larger screens.

plurals
  1. POHow delayed HTTP responses are handled by an app that have just gone to background?
    primarykey
    data
    text
    <p><strong>Background</strong></p> <ol> <li><p>A user of my app does something with my app, that schedules asynchronous AFNetworking HTTP request with some completion handler. </p></li> <li><p>Then, without a delay, user of my app goes to a home screen so my app enters to a background. </p></li> </ol> <p>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.</p> <p><strong>Questions</strong></p> <ol> <li><p>What will happen to this network request and specifically to its completion handler?</p></li> <li><p>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></li> </ol> <p><strong>P.S.</strong></p> <p>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.</p> <hr> <p><strong>UPDATE 1</strong></p> <p>I did find a partial answer in the related topic: <a href="https://stackoverflow.com/questions/6889802/what-happens-to-tasks-in-dispatch-queues-when-an-app-enters-inactive-background?rq=1">What happens to tasks in dispatch queues when an app enters inactive/background/suspended states in iOS?</a>.</p> <p>I'll quote it shortly:</p> <blockquote> <p>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.</p> </blockquote> <p>The most simple test I tried is the following:</p> <pre><code>- (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; } </code></pre> <p>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.</p> <hr> <p>What <strong>I still don't understand</strong> 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!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload