问题
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