无法endBackgroundTask:标识符4不存在后台任务,或者它可能已经结束 [英] Can't endBackgroundTask: no background task exists with identifier 4, or it may have already been ended

查看:15004
本文介绍了无法endBackgroundTask:标识符4不存在后台任务,或者它可能已经结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在后台实现了计时器,如下所示并使用XCode 4.5.2

Implemented the timer in the background as follows and using the XCode 4.5.2

UIDevice *device = [UIDevice currentDevice];
    BOOL backgroundSupported = NO;
    if ([device respondsToSelector:@selector(isMultitaskingSupported)]) {
        backgroundSupported = YES;
    }

    if (backgroundSupported) 
    {
        bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ 
            [[UIApplication sharedApplication] endBackgroundTask:bgTask];
        }];

      /*timer code goes here*/
    }

我的应用程序在后台运行,我在AppDelegate的 applicationDidEnterBackground 方法中有上面的代码,并在gdb中获取以下消息

and my app is running in background and I have the above code in applicationDidEnterBackground method in AppDelegate and getting the following message in gdb

无法endBackgroundTask:标识符4不存在后台任务,或者它可能已经结束。在UIApplicationEndBackgroundTaskError()中断以进行调试。

我知道这个问题类似于不能endBackgroundTask 但没有答案或建议。任何想法?

I know this question is similar to Can't endBackgroundTask but no answer or suggestions there. any ideas ?

推荐答案

确保你声明 bgTask ,如下所示: UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;

Make sure you are declaring bgTask like so: UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;

我想你可能有 bgTask 声明为int或NSNumber。

I think you may have bgTask declared as an int or NSNumber.

这篇关于无法endBackgroundTask:标识符4不存在后台任务,或者它可能已经结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆