如何在watchOS 3中使用HKWorkoutSession时记录mindfulSession?我可以在阅读和写作时要求mindfulSession权限,但是当我使用store.execute(query)
启动HKWorkoutSession时,我无法在 updateHanlder 中获得任何内容。 HKWorkoutSession的心率即使在后台也能完美运行。但是我无法弄清楚这是如何起作用的。 HKCategoryTypeIdentifier.mindfulSession
任何帮助将不胜感激。
谢谢,
答案 0 :(得分:2)
Swift 3:观看OS 3:好吧,我想通了。 HKCategoryTypeIdentifier.mindfulSession
用作类别类型,以将正念会话保存到健康商店。我实际上在watchOS 3上使用它来存储冥想会话。如下;
// Create Mindfulness category type
let categoryType = HKSampleType.categoryType(forIdentifier: HKCategoryTypeIdentifier.mindfulSession)
// Now create the sample
let smpleObject = HKCategorySample(type: sampleType!, value: HKCategoryValue.notApplicable.rawValue, start: Date().addingTimeInterval(-10000), end: Date())
// Finally save to health store
store.save(smpleObject) { (result:Bool, error:Error?) in
if result{
print("Saved")
}else{
print("error saving mindfulSession",error?.localizedDescription)
}
}
现在,如果您在iPhone上打开Health App,您应该会在正念部分看到一些数据。