Clean Bill of HealthKit

Clean Bill of HealthKit

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

Ff90de2297b7e3136fa3c4a971b0b1c5?s=128

Josh Johnson

October 07, 2014
Tweet

Transcript

  1. 1.

    Clean bill of HealthKit Making the most of health data

    Josh Johnson | Two Toasters | @jnjosh
  2. 5.
  3. 6.
  4. 7.
  5. 9.
  6. 15.

    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! }];
  7. 16.
  8. 17.
  9. 21.

    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];
  10. 23.
  11. 27.

    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! }]; //…
  12. 29.
  13. 31.
  14. 32.
  15. 33.
  16. 35.
  17. 37.