无法结束后台任务:不存在标识符为 1fd57580 的后台任务,或者它可能已经结束
Can't endBackgroundTask: no background task exists with identifier 1fd57580, or it may have already been ended
AppDelegate.m 文件包含
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIBackgroundTaskIdentifier taskID = [application beginBackgroundTaskWithExpirationHandler:^{
[application endBackgroundTask:taskID];
}];
}
我不知道为什么我在 gdb 中收到这条消息
Can't endBackgroundTask: no background task exists with identifier
1fd57580, or it may have already been ended. Break in
UIApplicationEndBackgroundTaskError() to debug.
你的代码全错了。它应该是这样的:
UIBackgroundTaskIdentifier taskID = [application beginBackgroundTaskWithExpirationHandler:^{
// Code to ensure your background processing stops executing
// so it reaches the call to endBackgroundTask:
}];
// Put the code you want executed in the background here
if (taskID != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:taskID];
}
如果您在后台使用位置更新,请在获取用户位置授权时添加以下代码。那是因为 Apple 将 allowsBackgroundLocationUpdates
的默认值从 iOS 9 开始更改为 NO
。
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
locationManager.allowsBackgroundLocationUpdates = YES;
}
AppDelegate.m 文件包含
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIBackgroundTaskIdentifier taskID = [application beginBackgroundTaskWithExpirationHandler:^{
[application endBackgroundTask:taskID];
}];
}
我不知道为什么我在 gdb 中收到这条消息
Can't endBackgroundTask: no background task exists with identifier 1fd57580, or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
你的代码全错了。它应该是这样的:
UIBackgroundTaskIdentifier taskID = [application beginBackgroundTaskWithExpirationHandler:^{
// Code to ensure your background processing stops executing
// so it reaches the call to endBackgroundTask:
}];
// Put the code you want executed in the background here
if (taskID != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:taskID];
}
如果您在后台使用位置更新,请在获取用户位置授权时添加以下代码。那是因为 Apple 将 allowsBackgroundLocationUpdates
的默认值从 iOS 9 开始更改为 NO
。
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
locationManager.allowsBackgroundLocationUpdates = YES;
}