The App Lifecycle
A hiker is logging a hike in TrailLog when a phone call comes in. They answer, then check messages, then come back ten minutes later — or never do, because iOS quietly ended the app to free memory. If TrailLog did not save in time, the half-written hike is gone.
The rule
Active, inactive, background, suspended — save before you leave the foreground.
An iOS app moves through a small set of states:
| State | What it means |
|---|---|
| Not running | Not launched, or ended by the system |
| Inactive | On screen but not receiving events — a call banner, Control Centre, a moment during launch |
| Active | On screen and receiving touches — the normal state |
| Background | Off screen, still running code for a short time |
| Suspended | In memory but frozen; no code runs. iOS may end it at any moment, with no warning |
The key fact is the last row: a suspended app can be terminated without being told. Anything not saved before the app reached the background may be lost.
In a UIKit app, two objects receive lifecycle events:
AppDelegate— process-wide events, most importantlyapplication(_:didFinishLaunchingWithOptions:), called once at launch for setup such as configuring services.SceneDelegate— events for one window (iOS 13 and later, when apps gained multiple windows on iPad):
func sceneDidBecomeActive(_ scene: UIScene) { resumeTracking() }
func sceneWillResignActive(_ scene: UIScene) { pauseTimer() }
func sceneDidEnterBackground(_ scene: UIScene) { journal.saveDraft() }
func sceneWillEnterForeground(_ scene: UIScene) { refreshWeather() }SwiftUI apps see the same states through the scenePhase environment value: .active, .inactive and .background.