SwiftUI アプリのフォアグランド・バックグランド遷移、処理する

Sceneの状態で処理
Example Code
import SwiftUI
struct ContentView: View {
@Environment(\.scenePhase) private var scenePhase
var body: some View {
Text("Hello, world!")
.onChange(of: scenePhase, perform: { value in
switch(value) {
case .active:
print("active")
case .background:
print("background")
case .inactive:
print("inactive")
@unknown default:
print("default")
}
})
}
}
バックグランドへ
inactive
↓
background
フォアグランドへ
inactive
↓
active






