App lifecycle and scene management

4084
0

iOS 13 introduced scene-based lifecycle for multi-window support on iPad. The App and Scene delegates handle different lifecycle events. SceneDelegate manages individual scenes—windows on iPad or the single window on iPhone. It responds to state transitions like foreground, background, and disconnect. AppDelegate handles app-level events like launch and termination. For SwiftUI apps, I use @main with App protocol and scene modifiers like .onOpenURL() for deep links. Background tasks require specific capabilities and scheduling with BGTaskScheduler. Understanding the lifecycle prevents bugs around state restoration, data persistence, and resource management.