swift - 如何将Apple Watch设置为防水模式?

标签 swift apple-watch

我已经安排好了游泳锻炼。

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/

相关文章:

swift - Date() 在调试中显示在 swift 5/Xcode 11 中损坏了吗?

ios - swift 观察者 (KVO) : Checking for Existence

ios - Apple Watch 上的推送通知

swift - 修改密码异常如何处理?

ios - 谷歌云功能通知 iOS

swift - 如何在底部面板中存储当前音频信息(AVAudioPlayer,Swift)

ios - 为现有的 iPhone 应用程序实现 WatchApp,并希望 api 调用在后台模式下发生在 iPhone 应用程序上

ios - 重启后 Apple Watch 4 启动时自动启动后台 WatchOS 应用程序

ios - 如何使用群组在 iPhone 和 Apple Watch 之间共享数据?

ios - Watchkit:在动态行中包含两个模板的表格