首页 > 解决方案 > 如何从健康应用程序的 HKSample 中获取严重性值

问题描述

我想显示来自 Health 应用程序的头痛数据。从 HealtStore 我得到一组 [HKSamles]。如何获得 HKCategoryValueSeverity?

从每个样本中,我可以获得 startDate、endDate 等。

sampleType 是 HKCategoryTypeIdentifierHeadache。目前我使用 HKSample 的 debugDescription 的第一个字符作为 HKCategoryValueSeverity.rawValue 的数字

我有一个 HealthKit HKSample 的 debugDescription。所以在下面的描述中,严重性 rawValue 是 4 -> .severe

4 1F6AED01-EB6A-4ADE-94C0-64F3F8B018BB " HKCategoryTypeIdentifierHeadache" (1), "iPhone13,3" (14.4) (2021-03-13 22:18:57 +0100 - 2021-03-13 22:28:57 +0100)

标签: iosswifthealthkit

解决方案


您获得查询的样本是具有属性值的 HKCategorySample 类型。看

https://developer.apple.com/documentation/healthkit/hkcategorysample?language=objc

对于头痛,与其他症状类型一样,value 是 HKCategoryValueSeverity 类型的枚举

https://developer.apple.com/documentation/healthkit/hkcategorytypeidentifierheadache?language=objc https://developer.apple.com/documentation/healthkit/hkcategoryvalueseverity?language=objc

您可以将值与可能的枚举列表进行比较以获取严重性。


推荐阅读