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?
精彩评论