Skip to content

Instantly share code, notes, and snippets.

@ramakser
Created March 5, 2016 21:53
Show Gist options
  • Save ramakser/6d9c7990e19aa669b555 to your computer and use it in GitHub Desktop.
Save ramakser/6d9c7990e19aa669b555 to your computer and use it in GitHub Desktop.
var backgroundUpdateTask: UIBackgroundTaskIdentifier = 0
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
self.backgroundUpdateTask = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({
self.endBackgroundUpdateTask()
})
}
func endBackgroundUpdateTask() {
UIApplication.sharedApplication().endBackgroundTask(self.backgroundUpdateTask)
self.backgroundUpdateTask = UIBackgroundTaskInvalid
}
func applicationWillEnterForeground(application: UIApplication) {
self.endBackgroundUpdateTask()
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment