Slide 1

Slide 1 text

Clean bill of HealthKit Making the most of health data Josh Johnson | Two Toasters | @jnjosh

Slide 2

Slide 2 text

“I’m not a doctor. I don’t even play one on TV.” — Me, just now.

Slide 3

Slide 3 text

“What is this, the Dark Ages?” — Doctor Leonard “Bones” McCoy

Slide 4

Slide 4 text

“Hello Computer” — Scotty

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

“So, What is is this HealthKit thing?” — You, hopefully.

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

The HealthKit Crash Course™

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

HKHealthStore // … [self.healthStore requestAuthorizationToShareTypes:writeTypes readTypes:readTypes completion:^(BOOL success, NSError *error) { // Do something! }];

Slide 14

Slide 14 text

HKObjectType HKQuantityType *stepType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; NSSet *writeTypes = [NSSet setWithObject:stepType]; NSSet *readTypes = [NSSet setWithObject:stepType];

Slide 15

Slide 15 text

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! }];

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

HKHealthStore [self.healthStore whatElseCanYouDo];

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

HKUnit HKQuantityType *stepQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; HKQuantity *stepQuantity = [HKQuantity quantityWithUnit:[HKUnit countUnit] doubleValue:stepCount]; // …

Slide 21

Slide 21 text

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];

Slide 22

Slide 22 text

HKHealthStore — Saving // … [self.healthStore saveObject:stepSample withCompletion:^(BOOL success, NSError *error) { // You better check that error. }];

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

HKHealthStore — Querying

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

HKHealthStore — Querying HKQuantityType *stepQuantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; NSPredicate *appPredicate = [HKSampleQuery predicateForObjectsFromSource:[HKSource defaultSource]]; //…

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

HKHealthStore — Querying //… stepQuery created [self.healthStore executeQuery:stepQuery];

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Demo

Slide 34

Slide 34 text

With great power comes great responsibility.

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Thank you! Questions? Josh Johnson | Two Toasters | @jnjosh

Slide 37

Slide 37 text

No content