Instance Method

sceneWillResignActive(_:)

Tells the delegate that the scene is about to resign the active state and stop responding to user events.

Declaration

optional func sceneWillResignActive(_ scene: UIScene)

Parameters

scene

The scene that is about to stop responding to user events.

Discussion

UIKit calls this method for temporary interruptions, such as when displaying system alerts. It also calls it before transitioning your app to the background state.

Use this method to quiet your interface and prepare it to stop interacting with the user. Specifically, pause ongoing tasks, disable timers, and decrease frame rates or stop updating your interface altogether. Games should use this method to pause the game. By the time this method returns, your app should be doing minimal work while it waits to transition to the background or to the foreground again.

If your scene has unsaved user data, save that data here to ensure that it isn't lost. However, never save data solely from this method. Instead, save it at appropriate points from your view controllers, usually in response to user actions. For example, save data when the user dismisses a data-entry screen. Do not rely on specific app transitions to save all of your app's critical data.

In addition to calling this method, UIKit also posts a willDeactivateNotification notification.

For more information about what to do when your app resigns the active state, see Preparing Your UI to Run in the Background.

See Also

Transitioning to the Background

func sceneDidEnterBackground(UIScene)

Tells the delegate that the scene is running in the background and is no longer onscreen.