Last active
August 20, 2024 09:21
-
-
Save quangtqag/d63f887c3a5426127840 to your computer and use it in GitHub Desktop.
Make app always call applicationWillTerminate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func applicationDidEnterBackground(application: UIApplication) { | |
// Create a pseudo background task to system call applicationWillTerminate when app enter background | |
// Default system will not call applicationWillTerminate when app enter background | |
// applicationWillTerminate only called when user close app in app switcher or some special cases of system | |
bgTask = application.beginBackgroundTaskWithExpirationHandler({ () -> Void in | |
application.endBackgroundTask(self.bgTask) | |
self.bgTask = UIBackgroundTaskInvalid | |
}) | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { () -> Void in | |
self.bgTask = UIBackgroundTaskInvalid | |
application.endBackgroundTask(self.bgTask) | |
} | |
} |
@quangtqag @Hazoomo @killann why do you "override" bgTask
and use application.endBackgroundTask(UIBackgroundTaskInvalid)
?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, could you please explain why we should dispatch on other queue task completion?
@quangtqag