I need to call some method on event when my app become foreground
(I'm using ViewModel for each view, so I can call sth not only from view)
As example:
my app is runned;
changed foreground window to Safari app.
Changed foreground window to my app -> some method called.
With .onChange(of: scenePhase) -> .active nothing happens with this scenario
so those code is not solution for me:
struct ContentView: View {
@Environment(\.scenePhase) private var scenePhase
var body: some View {
TestView()
.onChange(of: scenePhase) { phase in
switch phase {
case .active:
print("App is active")
default:
break
}
}
}
}
You could use the environment variable controlActiveState as follows:
@Environment(\.controlActiveState) var controlActiveState
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With