Skip to content

Instantly share code, notes, and snippets.

@apple-avadhesh
Created February 1, 2021 08:37
Show Gist options
  • Save apple-avadhesh/a26b2a6c8c1192d5609590ceefe47130 to your computer and use it in GitHub Desktop.
Save apple-avadhesh/a26b2a6c8c1192d5609590ceefe47130 to your computer and use it in GitHub Desktop.
SwiftUI App Life Cycle
@main
struct SwiftUIAppLifeCycle: App {
@Environment(\.scenePhase) var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { newScenePhase in
switch newScenePhase {
case .active:
print("App is active")
case .inactive:
print("App is inactive")
case .background:
print("App is in background")
@unknown default:
print("Received unexpected state")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment