如何让 Apple Watch 进入防水模式?

How to put Apple Watch into waterproof mode?

我已经安排好了游泳训练。

let configuration = HKWorkoutConfiguration()
configuration.activityType = .swimming
configuration.locationType = .outdoor

do {
    workoutSession = try HKWorkoutSession(configuration: configuration) 
    workoutSession!.delegate = self
    healthStore.start(workoutSession!)
} catch let error as NSError {
    // Perform proper error handling here...
    fatalError("*** Unable to create the workout session: \(error.localizedDescription) ***")
}

但我的客户说手表不会进入防水模式,除非他手动设置。

对于上下文,"waterproof lock" 是 Watch Series 2 在开始游泳锻炼时应该进入的模式。来自 an Apple Support article:

When you start a swimming workout, your Apple Watch automatically locks the screen with Water Lock to avoid accidental taps. When you're done, turn the Digital Crown to unlock the screen and clear any water from your Apple Watch. You hear sounds and may feel some water on your wrist.

此功能似乎不适用于我的应用程序。

我只有一个系列 0 可以测试,所以我无法确认我的代码在防水锁方面发生了什么。

我是不是遗漏了什么让手表强制进入防水模式的东西?

目前没有"waterproof mode"。我的客户的印象是有。

原生 Apple Exercise 应用程序有一个按钮,可以锁定手表并忽略交互,直到旋转数字表冠。这目前无法在第三方应用程序中重现。

我找到的解决方案是禁用手表应用程序上的所有按钮。这样一来,按钮就不会在水中时被意外敲击。用户必须用力触摸手表才能 re-enable 按钮。

自 watchOS 4 起可用: https://developer.apple.com/documentation/watchkit/wkextension/2868458-enablewaterlock

// Only an application which is in an active workout or location session and is foreground is allowed to enable water lock @available(watchOS 4.0, *) open func enableWaterLock()

开始游泳/水上锻炼时请拨打 WKExtension.shared().enableWaterLock()