ios - 如何使用 HKObserverquery 读取 iOS Healthkit 血压(收缩压、舒张压)?
<p><p>通过使用以下代码,当数据在 healthkit 中可用时,我可以使用观察者查询自动读取心率数据。</p>
<p>HKSampleType *readGlucoseType;</p>
<pre><code> readGlucoseType = ;
query = [initWithSampleType:readGlucoseType
predicate:nil
updateHandler:^(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError *error)
{
if (!error)
{
;
}
else
{
NSLog(@"Observerquery Error");
if (completionHandler)
{
completionHandler();
}
}
}];
;
</code></pre>
<p>我需要如何使用观察者查询从健康包中读取血压数据?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>更新了 Xcode 9.2 的答案:</p>
<pre><code>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? {
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)
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何使用 HKObserverquery 读取 iOS Healthkit 血压(收缩压、舒张压)?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/29073342/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/29073342/
</a>
</p>
页:
[1]