Instance Method

applicationWillResignActive(_:)

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

Declaration

optional func applicationWillResignActive(_ application: UIApplication)

Parameters

application

Your singleton app object.

Discussion

This method is called to let your app know that it is about to move from the 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 app and it begins the transition to the background state. An app in the inactive state continues to run but does not dispatch incoming events to responders.

You should 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. An app in the inactive state should do minimal work while it waits to transition to either the active or background state.

If your app has unsaved user data, you can save it here to ensure that it is not lost. However, it is recommended that you save user data at appropriate points throughout the execution of your app, usually in response to specific actions. For example, save data when the user dismisses a data entry screen. Do not rely on specific app state transitions to save all of your app’s critical data.

After calling this method, the app also posts a willResignActiveNotification notification to give interested objects a chance to respond to the transition.

See Also

Responding to App Life-Cycle Events

func applicationDidBecomeActive(UIApplication)

Tells the delegate that the app has become active.

func applicationDidEnterBackground(UIApplication)

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

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.