Health Kit WatchOs 3:如何记录mindfulSession?

时间:2016-08-28 01:05:18

标签: swift health-kit watch-os-3

如何在watchOS 3中使用HKWorkoutSession时记录mindfulSession?我可以在阅读和写作时要求mindfulSession权限,但是当我使用store.execute(query)启动HKWorkoutSession时,我无法在 updateHanlder 中获得任何内容。 HKWorkoutSession的心率即使在后台也能完美运行。但是我无法弄清楚这是如何起作用的。 HKCategoryTypeIdentifier.mindfulSession

任何帮助将不胜感激。

谢谢,

1 个答案:

答案 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,您应该会在正念部分看到一些数据。