How to update the value of a state variable when app lifecycle changes in SwiftUI ?

@Environment(\.presentationMode) private var presentationMode
.onChange(of: scenePhase) { newScenePhase in
switch
newScenePhase {
case .active:
//open QR Scanner when app is resumed
self.QRScannerisPresented = true
return
case
.background:
//app moves to backgound
return
case
.inactive:
return
@unknown
default:
return
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Valentin Quelquejay

Valentin Quelquejay

🇨🇭Cybersecurity student. DJ & Musician. Interested about too much things. Improving every minute.