Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2015 11:54
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