0
我正在使用beginBackgroundTaskWithExpirationHandler
方法在applicationDidEnterBackground
委託方法中保持NSTimer
繼續運行。但是如果長時間在後臺留下(在我的情況下7-10分鐘),應用程序會在很長一段時間後死亡。我不希望我的應用程序被殺,並且我希望計時器在後臺運行。我該如何擺脫這個問題。以下是我寫的applicationDidEnterBackground
方法應用程序如果使用beginBackgroundTaskWithExpirationHandler IOS
- (void)applicationDidEnterBackground:(UIApplication *)application {
if ([application respondsToSelector:@selector(setKeepAliveTimeout:handler:)]) {
[application setKeepAliveTimeout:600 handler:^{
DDLogVerbose(@"KeepAliveHandler");
// Do other keep alive stuff here.
}];
}
/*
* The following code is used to make the app running in background state as certain features
* (eg: NSTimer) doesn not run if its in background or if the phone is locked
*/
UIBackgroundTaskIdentifier locationUpdater =[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:locationUpdater];
} ];
}
那麼如何解決這個問題呢? – user1512727 2015-02-23 13:16:02
如果你描述你想要做的事情,我們可能會提供替代品,但是,一般來說,iOS不允許任意應用程序繼續在後臺運行。 – Rob 2015-02-23 13:51:55