gpt4 book ai didi

ios - UNUserNotification 是否可以选择仅在 Apple Watch 上显示通知?

转载 作者:行者123 更新时间:2023-11-28 12:21:37 25 4
gpt4 key购买 nike

我正在开发 Apple Watch 应用程序,它具有在每 2 或 3 或 5 分钟后向用户显示通知的功能。

我已经通过 iOS UNUserNotification 实现了这个功能,并且效果很好。

但我想要的是用户只能在 Apple Watch 而不是 iPhone 上看到所有通知。

现在它正在 iPhone 和 Apple Watch 上显示。

是否可以只在 Apple Watch 上显示通知?

我已经为 UserNotification 实现了以下代码。

func scheduleNotification(at date: Date) {


let trigger = UNTimeIntervalNotificationTrigger(timeInterval: (1*60), repeats: true)

let content = UNMutableNotificationContent()
content.title = "Test Reminder"
content.body = "Show More detail in Body!"
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "myCategory"

if let path = Bundle.main.path(forResource: "logo", ofType: "png") {
let url = URL(fileURLWithPath: path)

do {
let attachment = try UNNotificationAttachment(identifier: "logo", url: url, options: nil)
content.attachments = [attachment]
} catch {
print("The attachment was not loaded.")
}
}

let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger)

UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
}

提前致谢!

最佳答案

不,这是不可能的。系统自动决定在何处显示通知,开发人员对此无法控制。如果配对的 iPhone 被锁定并且 Watch 被用户佩戴,通知将显示在 Apple Watch 上。在任何其他情况下,通知将显示在 iPhone 上。

参见 Notifications on your Apple Watch

关于ios - UNUserNotification 是否可以选择仅在 Apple Watch 上显示通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44626300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com