Instance Method


Tells the delegate that the app is now in the background.


optional func applicationDidEnterBackground(_ application: UIApplication)



Your singleton app object.


Use this method to release shared resources, invalidate timers, and store enough app state information to restore your app to its current state in case it is terminated later. You should also disable updates to your app’s user interface and avoid using some types of shared system resources (such as the user’s contacts database). It is also imperative that you avoid using OpenGL ES in the background.

Your implementation of this method has approximately five seconds to perform any tasks and return. If you need additional time to perform any final tasks, you can request additional execution time from the system by calling beginBackgroundTask(expirationHandler:). In practice, you should return from applicationDidEnterBackground(_:) as quickly as possible. If the method does not return before time runs out your app is terminated and purged from memory.

You should perform any tasks relating to adjusting your user interface before this method exits but other tasks (such as saving state) should be moved to a concurrent dispatch queue or secondary thread as needed. Because it's likely any background tasks you start in applicationDidEnterBackground(_:) will not run until after that method exits, you should request additional background execution time before starting those tasks. In other words, first call beginBackgroundTask(expirationHandler:) and then run the task on a dispatch queue or secondary thread.

The app also posts a didEnterBackgroundNotification notification around the same time it calls this method to give interested objects a chance to respond to the transition.

For more information about how to transition gracefully to the background, and for information about how to start background tasks, see App Programming Guide for iOS.

See Also

Responding to App Life-Cycle Events

func applicationDidBecomeActive(UIApplication)

Tells the delegate that the app has become active.

func applicationWillResignActive(UIApplication)

Tells the delegate that the app is about to become inactive.

func applicationWillEnterForeground(UIApplication)

Tells the delegate that the app is about to enter the foreground.

func applicationWillTerminate(UIApplication)

Tells the delegate when the app is about to terminate.

class let didEnterBackgroundNotification: NSNotification.Name

Posted when the app enters the background.

class let willEnterForegroundNotification: NSNotification.Name

Posted shortly before an app leaves the background state on its way to becoming the active app.

class let willResignActiveNotification: NSNotification.Name

Posted when the app is no longer active and loses focus.

class let willTerminateNotification: NSNotification.Name

Posted when the app is about to terminate.