在 Apple 的Frontmost App Behavior文档中,指出
“[...] 当最前面的应用程序收到通知时,它可以播放触觉反馈或自定义声音,而不是显示通知警报,然后更新其用户界面。”
但是,我无法实现这一点。现在,按下按钮后,我在安排通知之前将应用程序声明为最前面:
@IBAction func StartButtonPressed() {
WKExtension.shared().isFrontmostTimeoutExtended = true
scheduleNotification()
}
当应用程序在前台收到通知时,它会播放一个触觉:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
//MARK: Handle foreground notification here
WKInterfaceDevice.current().play(.success)
print("Foreground notification received")
return
}
这在用户的手腕抬起时有效,但在用户点击按钮后降低手腕时无效。当手腕抬起或放下时,控制台会打印收到的前台通知。
如果不是播放触觉,我设置completionHandler([.alert,.sound])
通知在手腕抬起或放下时提醒用户。这是我想要的行为,但仅限于触觉。
我该如何实施?