ios - 如何从 HealthKit 运行锻炼中获取海拔增益、步频和运行配速?

标签 ios swift apple-watch healthkit

我需要从 AppleWatch 获取海拔增益、节奏和运行配速(不是平均值,而是每公里)锻炼数据。

有什么方法可以访问这些数据。目前我可以访问锻炼的持续时间、覆盖的距离……有这些的元数据吗?我在 Apple 的 HealthKit 文档中找不到任何内容。

我现在发现我必须查询stepCount和distanceCovered才能获得配速和节奏,但仍然无法访问海拔增益数据。

最佳答案

如果 workout 是您的 HKWorkout 对象,那么您可以执行以下操作:

if let workoutMetadata = workout.metadata {
    if let workoutElevation = workoutMetadata["HKElevationAscended"] as? HKQuantity {
        print("Elevation = \(workoutElevation.doubleValue(for: HKUnit.meter()))m")
    }
}

有些值不能作为属性使用,这似乎有点奇怪。我想这是因为它们只适用于有限数量的锻炼类型。

关于ios - 如何从 HealthKit 运行锻炼中获取海拔增益、步频和运行配速?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66375555/

相关文章:

ios - 基于字符串数组 (Swift) 在 UITableView 中的 viewdidload 上选择单元格

ios - 从 iOS 打开 WatchKit 应用程序

ios - 正则表达式仅用于UITextfield中的名称

iOS 验证存档因 CFBundleIdentifier 冲突和无效包而失败

ios - 如何在 Swift 中使用下面的 rangeOfString

avfoundation - Apple Watch 可以使用 AVFoundation 吗?

ios - 应用程序在模拟器中运行但不在 Apple Watch 上

ios - 无法更改 UITableView 中节标题的文本属性

ios - 是否使用 Game Center 实现成就?

ios - 在 Swift 3.0 中访问从 iTunes API 解析的 JSON 对象