Skip to content

Instantly share code, notes, and snippets.

@aheze
Created June 23, 2020 01:33
Show Gist options
  • Select an option

  • Save aheze/b98f9e5f6a086abcd62832f0ed95edca to your computer and use it in GitHub Desktop.

Select an option

Save aheze/b98f9e5f6a086abcd62832f0ed95edca to your computer and use it in GitHub Desktop.
@main
struct HelloWorldApp: App {
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .active:
print("scene is now active!")
case .inactive:
print("scene is now inactive!")
case .background:
print("scene is now in the background!")
@unknown default:
print("Apple must have added something new!")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment