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卡鎖定或主屏幕時收到通知,或者手錶在屏幕變黑時不通過移動手臂。
我正在尋找的是一個簡單的嘟嘟聲,我甚至不需要通知提醒屏幕。
如果你有這方面的工作或確認這個功能不工作在手錶上,請發佈代碼。
感謝
格雷格