iOS App States: From Launch to Suspension

An iOS app is like a person with different states of alertness: focused (Active), distracted (Inactive), or napping (Background/Suspended). This lifecycle dictates how your app behaves during interruptions.
WHY IT EXISTS: iOS is a resource-constrained environment, especially for battery and memory. The app lifecycle model exists to ensure a responsive user experience and preserve battery life by strictly managing what apps can do and when, especially when they aren't the frontmost app.
THE MENTAL MODEL: Think of your app's state like a person's level of consciousness. NOT RUNNING is asleep and unaware. INACTIVE is awake but distracted, like when a phone call comes in over your app. ACTIVE is fully engaged with the user. BACKGROUND is not on-screen but can still perform short, finite tasks. SUSPENDED is in memory but completely frozen, like being in cryo-stasis, executing no code but ready to be thawed quickly.
HOW IT WORKS: When a user launches your app, it moves from NOT RUNNING to INACTIVE and then to ACTIVE. If a system alert appears, it transitions to INACTIVE. When the user presses the Home button, it moves to BACKGROUND. Here, it gets a short window of time to finish crucial tasks, like saving user data. After that, the system moves it to the SUSPENDED state. A suspended app stays in memory but executes no code. If the system experiences memory pressure, it may purge suspended apps to free up resources, moving them back to NOT RUNNING without any further notification.
WHEN TO USE IT: You don't choose a state, you react to state transitions. Your app's delegate object (AppDelegate or SceneDelegate) receives callbacks for these changes, like applicationDidEnterBackground. You use these callbacks to save user data, pause games, stop timers, and release large memory resources before the app is suspended. This prevents data loss and makes your app a good citizen of the OS.
WHEN NOT TO USE IT: Don't try to fight the system. Avoid attempting to run long, continuous tasks in the background unless you have explicitly registered for a specific background execution mode (like audio playback or location updates). Trying to trick the system into letting your app run indefinitely in the background will cause it to be terminated by the system's watchdog process.
ONE CANONICAL EXAMPLE: A user is editing a document in a text editor app (ACTIVE state). They swipe to go to the Home Screen. The app gets a sceneDidEnterBackground notification. In response, the app's code immediately saves the current text to a file on disk. The app is then moved to SUSPENDED. Later, if the system terminates the app due to low memory, the user's work is safe. When they relaunch the app, it can load the document from the saved file.
Read the original → developer.apple.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.