首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Health 3:如何记录mindfulSession?

Health 3:如何记录mindfulSession?
EN

Stack Overflow用户
提问于 2016-08-28 01:05:17
回答 1查看 490关注 0票数 1

如何在mindfulSession 3中使用HKWorkoutSession记录watchOS?我可以请求mindfulSession的读写权限,但是当我使用store.execute(query)启动HKWorkoutSession时,我在store.execute(query)中什么也得不到即使在背景下,HKWorkoutSession的心率也能很好地工作。但我想不出这是怎么回事。HKCategoryTypeIdentifier.mindfulSession

任何帮助都将不胜感激。

谢谢,

EN

回答 1

Stack Overflow用户

发布于 2016-08-28 09:23:20

Swift 3:看OS 3:,我想出来了。HKCategoryTypeIdentifier.mindfulSession作为类别类型用于将正念会话保存到健康存储区。实际上,我在watchOS 3上使用它来存储冥想会议。如下所示;

代码语言:javascript
复制
// 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,您应该会在“正念”部分看到一些数据。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39187143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档