如何在mindfulSession 3中使用HKWorkoutSession记录watchOS?我可以请求mindfulSession的读写权限,但是当我使用store.execute(query)启动HKWorkoutSession时,我在store.execute(query)中什么也得不到即使在背景下,HKWorkoutSession的心率也能很好地工作。但我想不出这是怎么回事。HKCategoryTypeIdentifier.mindfulSession
任何帮助都将不胜感激。
谢谢,
发布于 2016-08-28 09:23:20
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,您应该会在“正念”部分看到一些数据。
https://stackoverflow.com/questions/39187143
复制相似问题