//Starting a background task at quit time
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
// Do the work associated with the task, preferably in chunks.<span style="font-family: Arial, Helvetica, sans-serif;">//如果要提前结束:</span><span style="color: rgb(68, 68, 68); font-family: Menlo; font-size: 10pt;">application</span><span style="color: rgb(68, 68, 68); font-size: 10pt; font-family: Menlo;">.backgroundTimeRemaining </span>