Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
iOS background task with all the checks and balances
class DoesSomethingInBackground
var backgroundTaskID: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid
func beginBackgroundTask() {
guard UIBackgroundTaskInvalid == backgroundTaskID else {return}
backgroundTaskID = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler { () -> Void in
func endBackgroundTask() {
guard UIBackgroundTaskInvalid != backgroundTaskID else {return}
let id = backgroundTaskID
backgroundTaskID = UIBackgroundTaskInvalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.