0
我正在开发苹果手表应用程序,它具有每2或3或5分钟后在之后向用户显示通知的功能。UNUserNotification是否可以选择仅在苹果手表上显示通知?
我已通过iOS UNUserNotification
及其作品完美实现了此功能。
但我想在这里是用户可以看到所有通知只在苹果手表不在iPhone上。
是否可以仅在Apple手表上显示通知?
在此先感谢!
我已经使用下面的代码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)")
}
}
}