How to register for foreground notifications for Watchkit in SwiftUI?

544 Views Asked by At

I want to get notified when the watch app enters foreground. How to register for "willEnterForegroundNotification" in SwiftUI. Following is the code to register for the same in UIKit.

Text("Hello, World!")
    .onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
        print("Moving back to the foreground!")
    }
1

There are 1 best solutions below

0
On

On watchOS 7 and above

NotificationCenter.default.publisher(for: WKExtension.applicationWillEnterForegroundNotification)