Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
iOS HKHealthStore request authorization
HKHealthStore *healthStore = [[HKHealthStore alloc] init];
// Share body mass, height and body mass index
NSSet *shareObjectTypes = [NSSet setWithObjects:
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass],
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight],
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex],
// Read date of birth, biological sex and step count
NSSet *readObjectTypes = [NSSet setWithObjects:
[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth],
[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierBiologicalSex],
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount],
// Request access
[healthStore requestAuthorizationToShareTypes:shareObjectTypes
completion:^(BOOL success, NSError *error) {
if(success == YES)
// ...
// Determine if it was an error or if the
// user just canceld the authorization request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.