Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When the application enters the background if it requires additional time to complete some task you will want to notify the OS of that. The detailed documentation is here: <a href="http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html" rel="nofollow">http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html</a>. Here's a quick and dirty patch.</p> <pre><code>- (void)applicationDidEnterBackground:(UIApplication *)application { __block UIBackgroundTaskIdentifier backgroundTask; //Create a task object backgroundTask = [application beginBackgroundTaskWithExpirationHandler: ^ { [application endBackgroundTask:background_task]; backgroundTask = UIBackgroundTaskInvalid; //Set the task to be invalid }]; dispatch_queue_t opQ = dispatch_queue_create("com.myapp.network", NULL); dispatch_async(opQ, ^{ [self sendNetworkData1]; [self sendNetworkData2]; [self sendNetworkData3]; [application endBackgroundTask:background_task]; backgroundTask = UIBackgroundTaskInvalid; //Set the task to be invalid }); } </code></pre> <p>The bottom line is that you notify that the application needs to run in the background with beginBackgroundTaskWithExpirationHandler: THen when your done you call endBackgroundTask: to notify the OS that you are finished processing in the background. And finally make sure that you reset the backgroundTask variable to UIBackgroundTaskInvalid.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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