ios - 无法结束 BackgroundTask : no background task exists with identifier 1fd57580, 或者它可能已经结束

标签 ios xcode6

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];
}

关于ios - 无法结束 BackgroundTask : no background task exists with identifier 1fd57580, 或者它可能已经结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33295384/

相关文章:

ios - 在 IOS 7 中为 UIToolBar 设置标题

ios - 为什么不能将属性观察器添加到惰性属性中?

ios - 从 JSON 文件中读取国家名称问题

ios - 如何在 Apple Watch 中创建构建(.ipa 或 .app)

ios - 如何使用 Xamarin iOS 共享 URL

ios - 如何下载iOS私钥证书分发?

installation - 如何在外部驱动器上安装 Xcode 6 或 7?

swift - 如何以编程方式在 Swift 中垂直居中标签?

ios - Xcode 中的“找不到框架”

ios - swift - 警告 : Attempt to present * on * while a presentation is in progress