0
我有工作的手表前景通知背景通知
UNUserNotificationCenter.current().delegate = self
收到前景通知:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void)
{
print("Received Notification .....")
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
let completionSound: UNNotificationPresentationOptions = [.sound, .alert]
completionHandler(completionSound)
}
加通知:
let content: UNMutableNotificationContent = UNMutableNotificationContent()
content.title = "TITLE"
content.subtitle = "sub title"
content.body = "message body"
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: duration, repeats: false)
let request = UNNotificationRequest(identifier: restOverIdentifier,
content: content,
trigger: trigger)
UNUserNotificationCenter.current().add(request)
{
(error) in // ...
}
我已经尝试了SIM卡和设备,但没有运气在SIM卡锁定或主屏幕时收到通知,或者手表在屏幕变黑时不通过移动手臂。
我正在寻找的是一个简单的嘟嘟声,我甚至不需要通知提醒屏幕。
如果你有这方面的工作或确认这个功能不工作在手表上,请发布代码。
感谢
格雷格