Created
February 1, 2021 08:37
-
-
Save apple-avadhesh/a26b2a6c8c1192d5609590ceefe47130 to your computer and use it in GitHub Desktop.
SwiftUI App Life Cycle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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