我试图通过使用 HKQuery.predicateForObjects 并使用以下代码放置过滤器来从HealthKit iOS中获取心率数据:
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
}
我尝试了不同的组合以不同的方式放置值
let谓词= HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyHeartRateMotionContext,allowedValues:[“ 1”])
OR
let谓词= HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyHeartRateMotionContext,allowedValues:[“ active”])
OR
let谓词= HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyHeartRateMotionContext,allowedValues: [HKHeartRateMotionContext.sedantary])
如果代码中的某处做错了什么,我就不会明白。
请纠正我。