不能endBackgroundTask:标识符4不存在后台任务,或者可能已经结束
在后台执行定时器,使用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中获得以下消息
不能endBackgroundTask:标识符4不存在后台任务,或者可能已经结束。 在UIApplicationEndBackgroundTaskError()中进行debugging。
我知道这个问题类似于不能endBackgroundTask,但没有答案或build议。 有任何想法吗 ?
确保你是这样声明bgTask
: UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
我想你可能有bgTask
声明为int或NSNumber。