Created
August 18, 2023 23:02
-
-
Save foxicode/604fcf042d552161ac90d9aa3a796527 to your computer and use it in GitHub Desktop.
App lifecycle handling in SwiftUI
This file contains 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
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