UIApplication Lifecycle

The interviewer asks

“What are the main UIApplication lifecycle events?”

How to answer

Since iOS 13 the lifecycle is split in two. The app delegate handles process-level events: launch (willFinishLaunching / didFinishLaunching), scene configuration and discarding, memory warnings and termination. The scene delegate handles UI state for each window: will-enter-foreground, did-become-active, will-resign-active and did-enter-background. The app-delegate versions of those four callbacks are marked deprecated in iOS 26 in the SDK (implementing them gives no warning, but they aren't called once you adopt scenes), and per TN3187, an app built with the iOS 27 SDK that hasn't adopted the UIScene life cycle won't launch. Adopting scenes is the requirement; supporting multiple windows is not.

Key points

  • States: not running → inactive → active ↔ inactive → background → suspended (and possibly terminated by the system without notice)
  • App delegate: application(_:didFinishLaunchingWithOptions:) for process setup (logging, DI container, BGTaskScheduler registration); application(_:configurationForConnecting:options:); application(_:didDiscardSceneSessions:); applicationDidReceiveMemoryWarning; applicationWillTerminate (not guaranteed to run)
  • Scene delegate: scene(_:willConnectTo:options:) builds the window and handles launch URLs or activities; sceneWillEnterForeground, sceneDidBecomeActive, sceneWillResignActive, sceneDidEnterBackground
  • Once scenes are adopted, applicationDidBecomeActive and friends are not called. For app-wide observers, use UIApplication.didBecomeActiveNotification and the other app-level notifications
  • URL handling moves too: application(_:open:options:) is deprecated since iOS 26 (warning) in favour of scene(_:openURLContexts:) plus connectionOptions.urlContexts on cold launch
  • SwiftUI App life-cycle apps already use scenes and meet the requirement

If they dig deeper

"What breaks when you rebuild a legacy app with Xcode 27?" Without UIApplicationSceneManifest in the Info.plist and a scene delegate, the app won't launch. After you migrate, code in applicationDidEnterBackground silently stops running until you move it to sceneDidEnterBackground. AppDelegate.window is nil, so UIApplication.shared.delegate?.window lookups break, and so does key-window hunting through UIApplication.shared.windows (use the scene's keyWindow). Deep links handled only in application(_:open:options:) get lost on cold launch. Separately, a launch screen is required for App Store submission starting with iOS 27. Also worth knowing: background time is limited (beginBackgroundTask), so save state in sceneDidEnterBackground, not applicationWillTerminate.

Common pitfalls

Treating "inactive" as "background" (inactive also happens for Control Center, incoming calls and the app switcher). Doing heavy synchronous work in didFinishLaunching, which delays the first frame and can get the app killed by the launch watchdog. Assuming one scene means one app state: on iPad each window has its own foreground/background state. Relying on applicationWillTerminate to save data, since suspended apps are killed without it.

How to use it

App-level setup stays in the app delegate; everything about UI state goes to the scene.

swift
import UIKit

@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        AppServices.configure()          // logging, DI, BGTaskScheduler registration
        return true
    }

    func application(_ application: UIApplication,
                     configurationForConnecting session: UISceneSession,
                     options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        UISceneConfiguration(name: "Default Configuration", sessionRole: session.role)
    }

    func applicationDidReceiveMemoryWarning(_ application: UIApplication) {
        AppServices.purgeCaches()        // still an app-level event
    }
}
swift
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession,
               options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = scene as? UIWindowScene else { return }
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = RootViewController()
        window.makeKeyAndVisible()
        self.window = window
        if let url = connectionOptions.urlContexts.first?.url { DeepLinks.open(url) }  // cold launch
    }

    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        URLContexts.first.map { DeepLinks.open($0.url) }                               // warm
    }

    func sceneDidBecomeActive(_ scene: UIScene) { }    // resume timers, refresh
    func sceneWillResignActive(_ scene: UIScene) { }   // pause games, media
    func sceneDidEnterBackground(_ scene: UIScene) {   // save state, release big resources
        Store.shared.save()
    }
}

The Info.plist needs a UIApplicationSceneManifest entry (UIApplicationSupportsMultipleScenes can stay NO), with a UIWindowSceneSessionRoleApplication configuration that names the delegate class ($(PRODUCT_MODULE_NAME).SceneDelegate).

Best practices

  • Adopt the scene life cycle now: it's mandatory for apps built with the iOS 27 SDK (TN3187), even for single-window iPhone apps
  • Keep the app delegate for process-wide work: launch setup, push registration, background task registration, scene configuration
  • Use sceneWillResignActive to pause and sceneDidEnterBackground to persist; don't count on applicationWillTerminate
  • Reach windows through the scene (view.window?.windowScene, windowScene.keyWindow), never UIApplication.shared.windows
  • Defer non-essential launch work until after the first frame (for example, a Task started from sceneDidBecomeActive)

Related concepts

  • UIScene multi-window, State restoration (stateRestorationActivity(for:)), Memory warnings, Background tasks, App launch time