Clean Bill of HealthKit

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

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

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

37 slides
  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! }]; //…

More Decks by Josh Johnson

Other Decks in Programming