iOS app state; everything you need to know

In iOS, there are five application states. While the operating system manages application state, critical tasks are controlled by the application itself to ensure smooth state changes.

The five states of an iOS application are as follows:

Not running:

The application was neither launched nor terminated by the user or the system.

Since the application is not running, there is no code to handle this state.

Inactive:

Although it is active in the foreground, the app does not receive any events. This state lasts only for a moment before the application switches to another state.

one example:

When a call is received, the app briefly goes into an inactive state and then switches to the background. In this case, the app is active in the foreground, but doesn't get events.

You can simply handle it in App Delegate:

func applicationWillResignActive(_ application: UIApplication) {
    // It is called in the App Delegate when the app is about to move from active to inactive state
    // For example, text message or a phone call is received
}

Active

The application runs in the foreground and receives events, such as the user clicking a button or entering some text.

You can simply handle it in App Delegate:

func applicationDidBecomeActive(_ application: UIApplicati

Guess you like

Origin blog.csdn.net/iCloudEnd/article/details/131390508