我的應用程序同步RSS提要約需15-30秒,併爲每個同步我請beginBackgroundTaskWithExpirationHandler:
。在iOS 7和iOS 8中,一切都很完美。endBackgroundTask:導致「終止由於信號9」
與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");
}
你在後臺線程? – matt
您好,是的同步方法是從另一個控制器使用被稱爲:dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^ { [syncManger startSync]; });剛更新的問題反映。謝謝! – TopReads
嗯,根據你所說的,我沒有很好的解釋。它可能是'sync'代碼中的東西,你沒有顯示的代碼?可以_什麼是使用太多內存?這可能是有道理的,因爲當你調用'endBackgroundTask'時,運行時會暫停你並發現你在後臺使用了太多的內存(在此之前,因爲你還在運行,所以你不能終止)。一般來說,我建議你認真對待這個信息:在進入後臺時,你應該已經嘗試釋放資源以減少內存使用量。 – matt