构建独立 watchOS 应用与连接蓝牙 LE 设备
1. 让手表振动
要让 Apple Watch 振动,可以使用苹果提供的单例 WKInterfaceDevice.captureDevice() 的 playHaptic(_:) 方法。苹果通过 WKHapticType 枚举提供了几种预配置的振动类型,其中 Notification 类型最为强烈,适合用于像 CarFinder 应用这样提醒用户返回车辆的场景。
以下是实现手表振动的代码示例:
func showAlert(timer: NSTimer) {
var reminderMessage = "Please return to your car"
if let userInfo = timer.userInfo as? [String: String] {
reminderMessage+="at \(userInfo["address"])"
}
print("Meter is out of time.")
WKInterfaceDevice.currentDevice().playHaptic(WKHapticType.Notification)
let okAction = WKAlertAction(title: "OK", style: WKAlertActionStyle.Default) { () -> Void in
print("OK b
超级会员免费看
订阅专栏 解锁全文
9

被折叠的 条评论
为什么被折叠?



