如何在 SwiftUI watchOS 上创建闹钟

How create alarm on SwiftUI watchOS

我想为我的 Apple Watch 创建闹钟应用程序,但我不知道如何叫醒一个人。有一个应用程序 - Sleep Cycle,它们会触发如图所示的东西:

手表像 Apple Watch 上的默认计时器应用一样不断振动。问题是这个界面元素的名称是什么?这不是通知,不是 Alert (https://developer.apple.com/documentation/swiftui/alert),不是 WKInterfaceDevice 播放函数。我只想重现这种行为。感谢您的帮助!

您需要的是 notifyUserWithHaptic,它会提供重复的触感,并且如果应用未处于活动状态,还会显示带有“打开”和“停止”按钮的通知样式屏幕。

根据 Apple 文档

For schedulable sessions such as smart alarms, call this method during the session to alert the user. When you call the method, the system plays repeating haptic feedback. If the app isn’t active, the system also displays a system alarm alert on the watch.

Link to Apple Documentation