Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created August 18, 2023 23:02
Show Gist options
  • Save foxicode/604fcf042d552161ac90d9aa3a796527 to your computer and use it in GitHub Desktop.
Save foxicode/604fcf042d552161ac90d9aa3a796527 to your computer and use it in GitHub Desktop.
App lifecycle handling in SwiftUI
import SwiftUI
@main
struct Swift2TestApp: App {
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}.onChange(of: scenePhase, perform: { scenePhase in
switch scenePhase {
case .background:
print("Background")
case .inactive:
print("Inavtive")
case .active:
print("Active")
@unknown default:
print("Unknown")
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment