开发者

How do I end a task gracefully in the expiration handler before iOS terminates the app?

开发者 https://www.devze.com 2023-03-24 03:26 出处:网络
We want to logout our app once the expiration handler is invoked.This works some of the time, but it appears there are times when it just kills the process hard even though we end the background task

We want to logout our app once the expiration handler is invoked. This works some of the time, but it appears there are times when it just kills the process hard even though we end the background task by calling endBackgroundTask. It almost seems like our logout process in this case is taking too long and iOS just kill开发者_运维百科s it. This shouldn't be a long task, but is there any way to request additional time?

 if ([app respondsToSelector:@selector(beginBackgroundTaskWithExpirationHandler:)]) {
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            // Synchronize the cleanup call on the main thread in case
            // the task actually finishes at around the same time.
            dispatch_async(dispatch_get_main_queue(), ^{
                if (bgTask != UIBackgroundTaskInvalid) {

                    backgroundKilled = true;

                    [self logoutAll]; 

                    [app endBackgroundTask:bgTask];
                                         bgTask = UIBackgroundTaskInvalid;
                }
            });
        }];
    }


Here is a good UIApplication delegate overview, covers what the app goes through when being terminated.


iOS gives you ten minutes for your background task. Is your logout process taking that long?

0

精彩评论

暂无评论...
验证码 换一张
取 消