How to filter “active” HeartRate from HealthKit iOS using predicate?

空扰寡人 提交于 2019-12-13 03:18:06

问题


I am trying to fetch Heart Rate Data from HealthKit iOS by putting filter using HKQuery.predicateForObjects By using the following code:

let predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyHeartRateMotionContext, allowedValues: ["active"])


        var interval = DateComponents()
        interval.day = 1
        let query = HKStatisticsCollectionQuery(quantityType: type, quantitySamplePredicate: predicate, options: [.discreteAverage], anchorDate: startDate, intervalComponents:interval)
        query.initialResultsHandler = { query, results, error in
            if error != nil {

                return
            }

I tried different combinations for putting values in a different way

let predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyHeartRateMotionContext, allowedValues: ["1"])

OR

let predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyHeartRateMotionContext, allowedValues: ["active"])

OR

let predicate = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyHeartRateMotionContext, allowedValues: [HKHeartRateMotionContext.sedantary])

I am not getting if am doing anything wrong somewhere in my code.

Please correct me.

Thanks in advance

来源:https://stackoverflow.com/questions/56234076/how-to-filter-active-heartrate-from-healthkit-ios-using-predicate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!