문제

I add long running task in Capabilities like 'background fetch' and add this code. Will it ok and I will have updates during all background app life?

- (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];
}
도움이 되었습니까?

해결책

No it won't work.

You can't schedule a timer to repeatedly fire while the app is in the background, even if you have added a background fetch or similar capability. Adding a background mode capability DOES NOT enable your app to run freely in the background, the background modes have limitations and restrictions.

There's many many many previous questions on this topic, do some searching and read them.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top