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

Ff90de2297b7e3136fa3c4a971b0b1c5?s=128

Josh Johnson

October 07, 2014
Tweet

Transcript

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

    Josh Johnson | Two Toasters | @jnjosh
  2. “I’m not a doctor. I don’t even play one on

    TV.” — Me, just now.
  3. “What is this, the Dark Ages?” — Doctor Leonard “Bones”

    McCoy
  4. “Hello Computer” — Scotty

  5. None
  6. None
  7. None
  8. “So, What is is this HealthKit thing?” — You, hopefully.

  9. None
  10. The HealthKit Crash Course™

  11. WWDC 2014 Session 203: Introducing HealthKit https://developer.apple.com/videos/wwdc/2014/?id=203

  12. HKHealthStore self.healthStore = [[HKHealthStore alloc] init];

  13. HKHealthStore // … [self.healthStore requestAuthorizationToShareTypes:writeTypes readTypes:readTypes completion:^(BOOL success, NSError *error)

    { // Do something! }];
  14. HKObjectType HKQuantityType *stepType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; NSSet *writeTypes = [NSSet

    setWithObject:stepType]; NSSet *readTypes = [NSSet setWithObject:stepType];
  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! }];
  16. None
  17. None
  18. HKHealthStore [self.healthStore whatElseCanYouDo];

  19. HKHealthStore — Saving HKQuantityType *stepQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; // …

  20. HKUnit HKQuantityType *stepQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; HKQuantity *stepQuantity = [HKQuantity

    quantityWithUnit:[HKUnit countUnit] doubleValue:stepCount]; // …
  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];
  22. HKHealthStore — Saving // … [self.healthStore saveObject:stepSample withCompletion:^(BOOL success, NSError

    *error) { // You better check that error. }];
  23. None
  24. HKHealthStore — Querying

  25. HKHealthStore — Querying HKQuantityType *stepQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; //…

  26. HKHealthStore — Querying HKQuantityType *stepQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; NSPredicate *appPredicate

    = [HKSampleQuery predicateForObjectsFromSource:[HKSource defaultSource]]; //…
  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! }]; //…
  28. HKHealthStore — Querying //… stepQuery created [self.healthStore executeQuery:stepQuery];

  29. None
  30. “Let’s build something cool instead.” — All of us, just

    now.
  31. None
  32. None
  33. Demo

  34. With great power comes great responsibility.

  35. None
  36. Thank you! Questions? Josh Johnson | Two Toasters | @jnjosh

  37. None