Understand how the app delegate manages your app's high-level behavior.
UIKit apps are always in one of five states, which are shown in Figure 1. Apps start off not running. When the user explicitly launches the app, the app moves briefly to the inactive state before entering the active state. (An active app appears onscreen and is known as a foreground app.) Quitting an active app moves it offscreen and into the background state, where it stays until the system suspends it a short time later. At its discretion, the system may quietly terminate a suspended app, returning it to the not running state.
Your app’s current state defines what system resources are available to it. Because active apps are visible onscreen and must respond to user interactions, they have priority when it comes to using system resources. Background apps are not visible onscreen, and therefore have more limited access to system resources and receive limited execution time.
Manage Life Cycle Events
When your app transitions from one state to another, UIKit notifies your app delegate object—an object that conforms to the
UIApplication protocol. Use your app delegate to modify your app's behavior to match its new state. For example, when moving from the not running to inactive state, handle the launch-time tasks needed to prepare your app to run.
The system notifies your app delegate about the following transitions:
Launch. Your app transitions from the not running to the inactive or background state. Use this transition to prepare your app to run; see Responding to the Launch of Your App.
Activation. Your app transitions from the inactive to the active state. Prepare your app to run in the foreground and be visible onscreen; see Preparing Your App to Run in the Foreground.
Deactivation. Your app transitions from the active to the inactive state. Quiet your app, perhaps only temporarily; see Preparing Your App to Run in the Background.
Background execution. Your app transitions from the inactive or not running state to the background state. Prepare to handle only essential tasks while running offscreen; see Preparing Your App to Run in the Background.
Termination. Your app transitions from any running state to the not running state. (Suspended apps are not notified when they are terminated.) Cancel all tasks and prepare to exit; see
Manage Behavioral Events
Your app delegate also responds to some other important events:
Memory warnings. Reduce the amount of memory your app uses; see Responding to Memory Warnings.
Time changes. Update time-sensitive features of your app.
Protected data becomes available/unavailable. Manage files when the user locks or unlocks the device.
State restoration. Restore your app’s UI to its previous state, giving the appearance that your app never stopped running; see Preserving Your App's UI Across Launches.
Handoff tasks. Continue tasks started on another device.
Open URLs. Receive and open URLs sent to your app.
Inter-app communication. Receive data from a paired watchOS app.
File downloads. Receive files that your app downloaded using a
Although the app delegate is the primary place where you handle life cycle events, it is not the only place. For most events, UIKit also generates notifications that any object can observe. For a list of app-related notifications that you can observe, see
UIApplication. For more information about the methods you use to handle events, see