【发布时间】:2013-07-11 20:11:11
【问题描述】:
使用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 中收到以下消息
无法结束BackgroundTask:不存在标识符为4的后台任务,或者它可能已经结束。中断 UIApplicationEndBackgroundTaskError() 进行调试。
我知道这个问题类似于Can't endBackgroundTask,但那里没有答案或建议。有什么想法吗?
【问题讨论】:
-
bgtask的类型是什么?
标签: ios objective-c