SwiftUI app lifecycle: issues with ScenePhase and using AppDelegate adaptors
29 June 2024
SwiftUI introduced the ScenePhase
API in iOS 14 and macOS 11. This was SwiftUI’s answer to handling application lifecycle events. At the same time, SwiftUI introduced UIApplicationDelegateAdaptor
for iOS and NSApplicationDelegateAdaptor
for macOS, which allow you to provide an AppDelegate
on both platforms to receive additional application lifecycle events and other events that were missing from SwiftUI at the time. Unfortunately, many of those application event APIs are still missing and ScenePhase
has a number of bugs (or at least, unexpected behavior).