【发布时间】:2017-06-20 19:19:01
【问题描述】:
我正在尝试在带有按钮的 Apple Watch 模拟器上显示本地通知。这是代码:
@IBAction func buttonOne() {
print("button one pressed")
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Notified!", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: "This is a notification appearing!", arguments: nil)
// Deliver the notification in five seconds.
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5,
repeats: false)
// Schedule the notification.
let request = UNNotificationRequest(identifier: "Notify", content: content, trigger: trigger)
center.add(request) { (error : Error?) in
if let theError = error {
print(theError.localizedDescription)
} else {
print("successful notification")
}
}
}
控制台正在成功打印“成功通知”,但该通知从未出现在手表模拟器上。我不知道为什么会这样
【问题讨论】:
标签: xcode notifications watchkit