2014-05-08 156 views
-2

我在Capabilities(如「後臺提取」)中添加長時間運行的任務並添加此代碼。它會好嗎,我會在所有背景應用程序生活中更新?ios7中的長時間運行任務

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
    UIApplication *app = [UIApplication sharedApplication]; 
    UIBackgroundTaskIdentifier bgTask = 0; 
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ 
     [app endBackgroundTask:bgTask]; 
    }]; 

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(backgroundUpdate) userInfo:nil repeats:YES]; 
    [timer fire]; 
} 
+0

可能重複的[如何在ios7中運行後臺進程](http://stackoverflow.com/questions/22756480/how-to-run-process-in-background-in-ios7) –

+0

重複的問題的答案是不是很好,它誤導IMO – Gruntcakes

回答

1

不,它不會工作。

即使您添加了後臺提取或類似功能,您也無法安排計時器在應用程序處於後臺時重複觸發。 添加背景模式功能不會讓您的應用在後臺自由運行,背景模式有限制和限制。

關於此主題有許多許多以前的問題,做一些搜索和閱讀。