Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clean Bill of HealthKit

Clean Bill of HealthKit

An overview of HealthKit delivered at 360|iDev Min in Greenville, SC on October 7, 2014

Josh Johnson

October 07, 2014
Tweet

More Decks by Josh Johnson

Other Decks in Programming

Transcript

  1. Clean bill of HealthKit Making the most of health data

    Josh Johnson | Two Toasters | @jnjosh
  2. HKObjectType HKQuantityType *stepType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; NSSet *writeTypes = [NSSet

    setWithObject:stepType]; NSSet *readTypes = [NSSet setWithObject:stepType]; [self.healthStore requestAuthorizationToShareTypes:writeTypes readTypes:readTypes completion:^(BOOL success, NSError *error) { // Do something! }];
  3. HKQuantitySample HKQuantityType *stepQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; HKQuantity *stepQuantity = [HKQuantity

    quantityWithUnit:[HKUnit countUnit] doubleValue:stepCount]; HKQuantitySample *stepSample = [HKQuantitySample quantitySampleWithType:stepQuantityType quantity:stepQuantity startDate:someStartDate endDate:someEndDate];
  4. HKHealthStore — Querying HKQuantityType *stepQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; NSPredicate *appPredicate

    = [HKSampleQuery predicateForObjectsFromSource:[HKSource defaultSource]]; HKSampleQuery *stepQuery = [[HKSampleQuery alloc] initWithSampleType:stepQuantityType predicate:appPredicate limit:HKObjectQueryNoLimit sortDescriptors:nil resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) { // results will be delivered as HKSamples. In this case, HKQuantitySamples. // You should also handle that Error! }]; //…