Skip to content

Instantly share code, notes, and snippets.

@yfujiki
Created June 25, 2013 06:27
Show Gist options
  • Save yfujiki/5856393 to your computer and use it in GitHub Desktop.
Save yfujiki/5856393 to your computer and use it in GitHub Desktop.
Finish background task in iOS
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:
^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
// Now call methods doing network activity
// ...
// WHEN I KNOW THE LAST ACTION HAS COMPLETED USE THIS BLOCK OF CODE
if (bgTask != UIBackgroundTaskInvalid)
{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment