NSArray *quantityTypesUsedInApp = @[HKQuantityTypeIdentifierBodyMass,
HKQuantityTypeIdentifierHeight,
HKQuantityTypeIdentifierBodyMassIndex,
HKQuantityTypeIdentifierBodyFatPercentage,
HKQuantityTypeIdentifierLeanBodyMass];
for (NSString *identifier in quantityTypesUsedInApp) {
HKQuantityType *sampleType = [HKQuantityType quantityTypeForIdentifier:identifier];
NSSet *requestSampleUnit = [NSSet setWithObject:sampleType];
[self.healthKitStore preferredUnitsForQuantityTypes:requestSampleUnit completion:^(NSDictionary *preferredUnits, NSError *error) {
if (!error) {
HKUnit *unit = [preferredUnits objectForKey:sampleType];
NSLog(@"%@ : %@", sampleType.identifier, unit.unitString);
//sampleType enabled for read
} else {
switch (error.code) {
case 5:
NSLog(@"%@ access denied", sampleType.identifier);
//sampleType denied for read
break;
default:
NSLog(@"request preffered quantity types error: %@", error);
break;
}
}
}];
}