【问题标题】:Health Kit WatchOs 3: How do I record a mindfulSession?Healthkit WatchOs 3:如何记录正念会话?
【发布时间】:2016-08-28 01:05:17
【问题描述】:

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

任何帮助将不胜感激。

谢谢,

【问题讨论】:

    标签: swift healthkit watchos-3


    【解决方案1】:

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

    【讨论】:

    • 如果对您有用,请选择正确答案:D
    • 您的正念应用程序是否还会记录移动和锻炼环的分钟数?知道如何不让它这样做吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-07
    • 1970-01-01
    • 2015-01-22
    • 2018-03-05
    • 2019-02-14
    • 1970-01-01
    相关资源
    最近更新 更多