Skip to content

Instantly share code, notes, and snippets.

@Superbil
Created April 23, 2015 07:09
Show Gist options
  • Save Superbil/3d8f81c45ee021190138 to your computer and use it in GitHub Desktop.
Save Superbil/3d8f81c45ee021190138 to your computer and use it in GitHub Desktop.
iOS start background.m
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, NULL), ^{
// Do the work associated with the task.
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment