1

I have below logic which give app state: But i wanted to add logic when app move to foreground.

In Swift we have method. I am looking for something similar method in swiftui

func sceneWillEnterForeground(_ scene: UIScene) {

 

but in Swiftui i only have .active, .inactive and .background


     .onChange(of: scenePhase) { newPhase in
                if newPhase == .active {
                    
                } else if newPhase == .inactive {
                    
                } else if newPhase == .background {
                    
                }
            }
ios developer
  • 3,363
  • 3
  • 51
  • 111

1 Answers1

0

It is possible to use .onReceive with subscription to Notification Center publisher on UIScene.willEnterForegroundNotification notification, or, after all, mentioned scene delegate callback (having scene delegate as described in https://stackoverflow.com/a/60359809/12299030)

Asperi
  • 228,894
  • 20
  • 464
  • 690