How to register for foreground notifications for Watchkit in SwiftUI?

Viewed 396

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 Answers

On watchOS 7 and above

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