我想从我的 HKHealthStore 实例中获取用户最近的 BMI 读数。截至目前,我正在按照以下方式进行操作,但似乎不正确。有没有办法获得 BMI 的实际数值而不是 countUnit (HKUnit)?
HKQuantityType *bodyMassIndexType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex];
HKSampleQuery *bmiSampleQuery = [[HKSampleQuery alloc] initWithSampleType:bodyMassIndexType predicate:nil limit:1 sortDescriptors:nil resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {
if (results.count == 0)
{
//No results
}
else
{
if (!error)
{
NSString *bmiString = [NSString stringWithFormat:@"%@", [[results firstObject] quantity]];
NSString *parsedBMIString = [bmiString stringByReplacingOccurrencesOfString:@" count" withString:@""];
NSLog(@"%f", [parsedBMIString floatValue]);
}
}
}];
[self.store executeQuery:bmiSampleQuery];