我正在开发苹果手表应用程序,它的功能是在之后每2、3或5分钟向用户显示一次通知。
我已经通过iOS UNUserNotification实现了这个功能,并且它的工作非常完美。
但是我想要的是用户只能在苹果手表上看到所有的通知,而不是在iPhone上。
现在,它在iPhone和苹果手表上都能看到。
是否有可能只在苹果手表上显示通知?
我已经为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)")
}
}
}提前谢谢!
https://stackoverflow.com/questions/44626300
复制相似问题