我已经安排好了游泳锻炼。
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) ***")
}
但我的客户说 watch 不会进入防水模式,除非他手动制作。
就上下文而言,“防水锁定”是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.
此功能似乎不适用于我的应用。
我只有 Series 0 可供测试,因此我无法确认我的代码在防水锁方面发生了什么情况。
我是否缺少一些东西来让锻炼迫使 watch 进入防水模式?
最佳答案
自 watchOS 4 起可用: https://developer.apple.com/documentation/watchkit/wkextension/2868458-enablewaterlock
//只有处于事件锻炼或定位 session 且处于前台的应用程序才允许启用水锁
@可用(watchOS 4.0,*)
打开函数enableWaterLock()
开始游泳/水中锻炼时调用 WKExtension.shared().enableWaterLock()
。
关于swift - 如何将Apple Watch设置为防水模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42009032/