Created
October 10, 2012 21:33
-
-
Save jorgenpt/3868577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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