如何在HealthKit上记下会议记录?

时间:2019-10-02 11:54:11

标签: swift healthkit

我正在尝试将分钟记入健康应用程序,但出现错误:

  

_HKObjectValidationFailureException”,原因:“值2与类型HKCategoryTypeIdentifierMindfulSession不兼容

这是我的功能,金额是两倍

mysql

我该怎么办?

1 个答案:

答案 0 :(得分:4)

HKCategorySample的代码文档中,我们可以看到:

/**
 @property   value
 @discussion The preferred enum for the value is determined by the receiver's category type.
 */
open var value: Int { get }

这意味着每个类别都有自己的值枚举。 MindfullSession的this enum只有一个适用的值:HKCategoryValue.notApplicable

因此您的代码应如下所示:

let mindfullSample = HKCategorySample(type: mindfulType, value: HKCategoryValue.notApplicable.rawValue, start: Date(), end: Date() + amount)