xcode endBackgroundTask:导致“由于信号 9 终止”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33228366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
endBackgroundTask: Causing "Terminated due to signal 9"
提问by TopReads
My app syncs RSS feeds which takes about 15-30 seconds and for each sync I request beginBackgroundTaskWithExpirationHandler:
. In iOS 7 and iOS 8 everything worked perfectly.
我的应用程序同步 RSS 提要大约需要 15-30 秒,对于我请求的每次同步beginBackgroundTaskWithExpirationHandler:
。在 iOS 7 和 iOS 8 中一切正常。
Starting with iOS 9 calling [[UIApplication sharedApplication] endBackgroundTask: backgroundTask];
causes the app to crash with Message from debugger:
从 iOS 9 开始调用[[UIApplication sharedApplication] endBackgroundTask: backgroundTask];
会导致应用程序崩溃并显示来自调试器的消息:
Terminated due to signal 9.
由于信号 9 终止。
From my research, signal 9 means the app using too much memory. When I use instruments, the app never goes over 30mb or 40% cpu.
根据我的研究,信号 9 表示应用程序使用了过多内存。当我使用仪器时,应用程序永远不会超过 30mb 或 40% cpu。
I know that it's from calling endBackgroundTask:
because if I don't call it, the app doesn't crash. Yet, once I call endBackgroundTask: the app will crash every time.
我知道它来自调用,endBackgroundTask:
因为如果我不调用它,应用程序就不会崩溃。然而,一旦我调用 endBackgroundTask: 应用程序每次都会崩溃。
I'm not sure what's going wrong here. I've tried everything. Re-writting code, moving code around, commenting out everything except endBackgroundTask:. Any help or insight would be appreciated.
我不确定这里出了什么问题。我什么都试过了。重写代码,移动代码,注释掉除了 endBackgroundTask: 之外的所有内容。任何帮助或见解将不胜感激。
Here's the code:
这是代码:
@interface SyncClass ()
@property (nonatomic) UIBackgroundTaskIdentifier backgroundTask;
@end
-(void)startSync
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self beginBackgroundUpdateTask];
// I then call my syncing code [syncClass sync];
});
//When sync is done call endBackgroundTask
[self endBackgroundUpdateTask];
}
- (void) beginBackgroundUpdateTask
{
NSLog(@"Background Time:%f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[self endBackgroundUpdateTask];
}];
}
- (void) endBackgroundUpdateTask
{
[[UIApplication sharedApplication] endBackgroundTask: self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
NSLog(@"Ending background task");
}
采纳答案by TopReads
Answering my own question here. AFNetworking and FMDB happened to be out of date. Updating them through cocoa pods seems to have fixed the problem.
在这里回答我自己的问题。AFNetworking 和 FMDB 碰巧过时了。通过可可豆更新它们似乎解决了这个问题。