我想在 watch 应用进入前台时收到通知。如何在 SwiftUI 中注册“willEnterForegroundNotification”。以下是在 UIKit 中注册相同内容的代码。
Text("Hello, World!")
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
print("Moving back to the foreground!")
}
最佳答案
在 watchOS 7 及更高版本上
NotificationCenter.default.publisher(for: WKExtension.applicationWillEnterForegroundNotification)
关于swift - 如何在 SwiftUI 中为 Watchkit 注册前台通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60955722/