__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];//这里调用endBackgroundTask:bgTask是什么意思?后面队列block中又调用一次,这里是告诉系统后台任务完成?麻烦帮看一下,尽量解释清楚。 谢谢!
}];
// 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.
//UIBackgroundTaskInvalid
NSLog(@”Starting background task with %0.1f seconds remaining”, application.backgroundTimeRemaining);
[NSThread sleepForTimeInterval:600];
NSLog(@”Finishing background task with %0.1f seconds remaining”,application.backgroundTimeRemaining);
//告诉系统我们完成了
[application endBackgroundTask:bgTask];//这里又是什么意思?
});
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];//这里调用endBackgroundTask:bgTask是什么意思?后面队列block中又调用一次,这里是告诉系统后台任务完成?麻烦帮看一下,尽量解释清楚。 谢谢!
}];
// 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.
//UIBackgroundTaskInvalid
NSLog(@”Starting background task with %0.1f seconds remaining”, application.backgroundTimeRemaining);
[NSThread sleepForTimeInterval:600];
NSLog(@”Finishing background task with %0.1f seconds remaining”,application.backgroundTimeRemaining);
//告诉系统我们完成了
[application endBackgroundTask:bgTask];//这里又是什么意思?
});
解决方案
40
[application endBackgroundTask:bgTask];//这里调用endBackgroundTask:bgTask是什么意思?后面队列block中又调用一次,这里是告诉系统后台任务完成?麻烦帮看一下,尽量解释清楚。 谢谢!
bgTask:你创建的后台任务标记;
前面的endBackgroundTask:,是在后台任务执行时间超过了系统允许的时间,导致过期的回调函数,属于异常结束;
后面的endBackgroundTask:,是后台任务执行完成时,正常的结束任务;
bgTask:你创建的后台任务标记;
前面的endBackgroundTask:,是在后台任务执行时间超过了系统允许的时间,导致过期的回调函数,属于异常结束;
后面的endBackgroundTask:,是后台任务执行完成时,正常的结束任务;