- (void)applicationDidEnterBackground:(UIApplication *)application
{
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
//Check if device supports mulitasking
UIApplication *application = [UIApplication sharedApplication];
//Get the shared application instance
__block UIBackgroundTaskIdentifier background_task;
//Create a task object
background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {
[application endBackgroundTask: background_task];
/** Tell the system that we are done with the tasks **/
background_task = UIBackgroundTaskInvalid;
/** Set the task to be invalid **/
/** System will be shutting down the app at any point in time now **/
}];
/** Background tasks require you to use asyncrous tasks **/
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"\n\nRunning in the background!\n\n");
});
}
}