Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
I pull many data from HealthKit including nutritious, workouts, body mass, weight, height. I can get them all without any problem but what I want to do is to get those data's units as well. For example, if the user uses height property in meter or the inch or any other metric unit. I am doing in this way
Code:
lastHeight = [quantity doubleValueForUnit:[HKUnit meterUnit]];
it gives the right height number but if the user uses in inch unit I still display it in meters. How can I pull units as well for the appropriate property?
 
@chown33 thanks for the reply. I implemented the code now but it hits always error clause. I think it occurs because of the permission. How can I get permission from the user? Here how the code looks like
Code:
- (void) getHeightUnitWithHander:(void (^)(BOOL isSuccessful, NSString *errorText, HKQuantity *heightUnit)) handler {
    
    NSSet *heightSet = [NSSet setWithObject:HKQuantityTypeIdentifierHeight];
    [self.healthStore preferredUnitsForQuantityTypes:heightSet completion:^(NSDictionary<HKQuantityType *,HKUnit *> *preferredUnits, NSError *error) {
        
        if (error) {
            NSLog(@"Error Unit %@", error.description);
        } else {
            NSLog(@"HEIGHT UNİTS %@", preferredUnits);
        }
    }];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.