在AppDelegate.m中加入如下代码即可。
- (void)applicationDidEnterBackground:(UIApplication *)application { if (kCFCoreFoundationVersionNumber > kCFCoreFoundationVersionNumber_iOS_5_1) { // Acquired additional time UIDevice *device = [UIDevice currentDevice]; BOOL backgroundSupported = NO; if ([device respondsToSelector:@selector(isMultitaskingSupported)]) { backgroundSupported = device.multitaskingSupported; } if (backgroundSupported) { __block UIBackgroundTaskIdentifier backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{ [application endBackgroundTask:backgroundTask]; backgroundTask = UIBackgroundTaskInvalid; }]; } } }