3

我想在手表应用程序进入前台时收到通知。如何在 SwiftUI 中注册“willEnterForegroundNotification”。以下是在 UIKit 中注册相同的代码。

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

1 回答 1

1

在 watchOS 7 及更高版本上

            NotificationCenter.default.publisher(for: WKExtension.applicationWillEnterForegroundNotification)
于 2020-10-15T17:26:07.573 回答