gpt4 book ai didi

swift - 健康工具包 WatchOs 3 : How do I record a mindfulSession?

转载 作者:行者123 更新时间:2023-11-28 12:42:09 25 4
gpt4 key购买 nike

在 watchOS 3 中使用 HKWorkoutSession 时如何录制 mindfulSession?我可以请求 mindfulSession 的读写权限,但是当我使用 store.execute(query) 启动 HKWorkoutSession 时,我在 updateHanlder 中没有得到任何东西. HKWorkoutSession 的心率即使在后台也能完美运行。但我无法弄清楚它是如何工作的。 HKCategoryTypeIdentifier.mindfulSession

任何帮助将不胜感激。

谢谢,

最佳答案

Swift 3:Watch OS 3:好吧,我明白了。 HKCategoryTypeIdentifier.mindfulSession 用作将正念 session 保存到健康商店的类别类型。我实际上在 watchOS 3 上使用它来存储冥想 session 。如下;

// 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 上打开健康应用程序,您应该会在正念部分看到一些数据。

关于swift - 健康工具包 WatchOs 3 : How do I record a mindfulSession?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39187143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com