通过使用以下代码,当数据在 healthkit 中可用时,我可以使用观察者查询自动读取心率数据。
HKSampleType *readGlucoseType;
readGlucoseType = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];
query = [[HKObserverQuery alloc]initWithSampleType:readGlucoseType
predicate:nil
updateHandler:^(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError *error)
{
if (!error)
{
[self handleHKQueryResponse:query completionHandler:completionHandler errorCode:error];
}
else
{
NSLog(@"Observerquery Error");
if (completionHandler)
{
completionHandler();
}
}
}];
[self.healthStore executeQuery:query];
我需要如何使用观察者查询从健康包中读取血压数据?
更新了 Xcode 9.2 的答案:
func readSampleByBloodPressure()
{
guard let type = HKQuantityType.correlationType(forIdentifier: HKCorrelationTypeIdentifier.bloodPressure),
let systolicType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureSystolic),
let diastolicType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureDiastolic) else {
return
}
let sampleQuery = HKSampleQuery(sampleType: type, predicate: nil, limit: 0, sortDescriptors: nil) { (sampleQuery, results, error) in
if let dataList = results as? [HKCorrelation] {
for data in dataList
{
if let data1 = data.objects(for: systolicType).first as? HKQuantitySample,
let data2 = data.objects(for: diastolicType).first as? HKQuantitySample {
let value1 = data1.quantity.doubleValue(for: HKUnit.millimeterOfMercury())
let value2 = data2.quantity.doubleValue(for: HKUnit.millimeterOfMercury())
print("\(value1) / \(value2)")
}
}
}
}
healthStore.execute(sampleQuery)
}
关于ios - 如何使用 HKObserverquery 读取 iOS Healthkit 血压(收缩压、舒张压)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29073342/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |