Skip to content

Instantly share code, notes, and snippets.

@TuenTuenna
Created August 29, 2022 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TuenTuenna/da87b5e4320fa614871ab3ec949bf6e4 to your computer and use it in GitHub Desktop.
Save TuenTuenna/da87b5e4320fa614871ab3ec949bf6e4 to your computer and use it in GitHub Desktop.
SwiftUi 앱 라이프사이클
import SwiftUI

@main
struct ScenePhaseApp: App {
    
    @Environment(\.scenePhase) var scenePhase
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .onChange(of: self.scenePhase, perform: { changedScenePhase in
            switch changedScenePhase {
            case .active:
                print("[scenePhase] active 앱이 켜진 직후 / 재진입")
            case .inactive:
                print("[scenePhase] inactive 앱 스위칭 할 수 있게 올린 상태")
            case .background:
                print("[scenePhase] background 아이폰 홈화면으로 나왔을 때")
            @unknown default:
                print("background")
            }
        })
//        applicationDidBecomeActive
//        applicationWillResignActive
//        applicationDidEnterBackground
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment