Skip to content

Instantly share code, notes, and snippets.

@jorgenpt
Created October 10, 2012 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgenpt/3868577 to your computer and use it in GitHub Desktop.
Save jorgenpt/3868577 to your computer and use it in GitHub Desktop.
- (void)keepAliveHandler:(UIBackgroundTaskIdentifier)bgIdentifier {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSLog(@"Runnin' in the background!");
for (int i = 49; i >= 1; --i) {
NSLog(@"Okay, %i more!", i);
[NSThread sleepForTimeInterval:6];
}
NSLog(@"Phew! Made it through!");
[[UIApplication sharedApplication] endBackgroundTask:bgIdentifier];
});
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application setKeepAliveTimeout:600
handler:^{
UIBackgroundTaskIdentifier bgIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"Runnin' out of time, cap'n!");
}];
[self keepAliveHandler:bgIdentifier];
}];
// ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment