gpt4 book ai didi

objective-c - 如何在 iOS 中读取 HealthKit 的血压数据?

转载 作者:太空狗 更新时间:2023-10-30 04:01:55 52 4
gpt4 key购买 nike

我在尝试弄清楚如何在 HealthKit 中读取血压数据时遇到问题,特别是因为了解 HKCorrelationQuery 如何为 Objective C 测量血压在开发者网站或教程中没有详细记录。

最佳答案

我使用以下代码通过 HealthKit 读取血压数据。我发现您无法直接读取收缩压或舒张压值。您需要为血压数据创建一个 HKCorrelationQuery,然后对于每个相关性,您需要进行一些挖掘以最终获得血压值。希望这对您有所帮助!

- (void)readBloodPressure {

HKQuantityType *systolicType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureSystolic];
HKQuantityType *diastolicType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureDiastolic];
HKCorrelationType *bloodPressureType =
[HKCorrelationType correlationTypeForIdentifier:HKCorrelationTypeIdentifierBloodPressure];

HKCorrelationQuery *query =
[[HKCorrelationQuery alloc]
initWithType:bloodPressureType predicate:nil
samplePredicates:nil
completion:^(HKCorrelationQuery *query, NSArray *correlations, NSError *error) {
if (correlations == nil) {
// Provide proper error handling here...
NSLog(@"An error occurred while searching for blood pressure data %@",
error.localizedDescription);
abort();
}
for (HKCorrelation *correlation in correlations) {
HKQuantitySample *systolicSample = [[correlation objectsForType:systolicType] anyObject];
HKQuantity *systolicQuantity = [systolicSample quantity];
HKQuantitySample *diastolicSample = [[correlation objectsForType:diastolicType] anyObject];
HKQuantity *diastolicQuantity = [diastolicSample quantity];
double systolicd = [systolicQuantity doubleValueForUnit:[HKUnit millimeterOfMercuryUnit]];
double diastolicd = [diastolicQuantity doubleValueForUnit:[HKUnit millimeterOfMercuryUnit]];
NSLog(@"Systolic %f",systolicd);
NSLog(@"Diastolic %f",diastolicd);
NSLog(@"Date %@",systolicSample.startDate);

[self saveBloodPressureIntoApp:systolicd withDiastolic:diastolicd withDate:systolicSample.startDate];


}

}];

[self.healthStore executeQuery:query];

}

关于objective-c - 如何在 iOS 中读取 HealthKit 的血压数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35006586/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com