endBackgroundTask:导致“由于信号9终止”

时间:2015-10-20 05:03:28

标签: ios xcode ios9

我的应用程序会同步RSS源,大约需要15-30秒,而且每次同步请求beginBackgroundTaskWithExpirationHandler:。在iOS 7和iOS 8中,一切都运行良好。

从iOS 9开始调用[[UIApplication sharedApplication] endBackgroundTask: backgroundTask];会导致应用程序因调试器的消息而崩溃:

  

由于信号9终止。

根据我的研究,信号9意味着应用程序使用了太多内存。当我使用乐器时,应用程序永远不会超过30mb或40%cpu。

我知道这是来自endBackgroundTask:,因为如果我不打电话,应用程序就不会崩溃。然而,一旦我调用endBackgroundTask:应用程序每次都会崩溃。

我不确定这里出了什么问题。我已经尝试了一切。重写代码,移动代码,注释除endBackgroundTask之外的所有内容:任何帮助或见解将不胜感激。

以下是代码:

    @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");
    }

1 个答案:

答案 0 :(得分:1)

在这里回答我自己的问题。 AFNetworking和FMDB恰好已经过时了。通过可可豆荚更新它们似乎解决了这个问题。