DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128)...

23
An Apple a Day: DEVELOPING APPS WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016

Transcript of DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128)...

Page 1: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

An Apple a Day: DEVELOPING APPS WITH HEALTHKIT

– Jonathan Wiley (@microchip128) 5.25.2016

Page 2: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

INTRODUCING

HealthKit

Page 3: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

What is HealthKit?Nashville CocoaHeads - HealthKit

Page 4: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

What can HealthKit store?• HEALTH SAMPLE DATA

• Body Measurements, such as weight • Fitness Measurements, such as active energy burned exercising,

walking & running distance, exercise minutes • Nutrition, such as fiber or caffeine • Sleep Analysis • Vitals, such as heart rate

• USER HEALTH CHARACTERISTIC DATA • Things that don’t change for a user, like birthdate and blood type

Nashville CocoaHeads - HealthKit

Page 5: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

What apps use HealthKit?

Nashville CocoaHeads - HealthKit

HeartBeat

Page 6: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

App Store ConsiderationsNashville CocoaHeads - HealthKit

Page 7: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

How do you code for HealthKit?

Page 8: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Getting Started: HealthKit Permissions

Nashville CocoaHeads - HealthKit

You must request read/write permission for each HealthKit type from a user

Page 9: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Getting Permissions in HeartBeat App CodeNashville CocoaHeads - HealthKit

TO THE CODE!

Page 10: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

How do you read from HealthKit?Nashville CocoaHeads - HealthKit

Direct method calls for characteristic data, such as dateOfBirthWithError:

For sample data • Statistics query • Statistics collection query • Correlation query • Source query • Activity summary query

Page 11: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

HealthKit Objects describe values in HealthKitNashville CocoaHeads - HealthKit

UUID Metadata Source Revision Device

Samples have additional properties • Type • Start Date • End Date

Page 12: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Units and QuantitiesNashville CocoaHeads - HealthKit

HKUnit is extremely powerful for converting readings into the proper unit

For instance, getting weight in pounds or grams can be done using HKUnit

Page 13: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Reading Age in HeartBeat App CodeNashville CocoaHeads - HealthKit

TO THE CODE!

Page 14: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

How do you stream data from HealthKit?Nashville CocoaHeads - HealthKit

• Observer query • Anchored object queries • Statistics collection query • Activity summary query

Page 15: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Streaming Heart Rate QueryNashville CocoaHeads - HealthKit

TO THE CODE!

Page 16: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

How do you write to HealthKit?Nashville CocoaHeads - HealthKit

• Get the HKObjectType for the sample you want to record

• Create a HKSample object for your sample with the sample values

• Save the object to the HealthKit store

Page 17: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Saving Workout CodeNashville CocoaHeads - HealthKit

TO THE CODE!

Page 18: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

DEMO TIME HeartBeat App

Page 19: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Use the Apple Watch to monitor heart rate more frequently with HKWorkoutSession

Nashville CocoaHeads - HealthKit

• Can start a type of workout and the Apple Watch will record accordingly

Page 20: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

HKWorkoutSession CodeNashville CocoaHeads - HealthKit

TO THE CODE!

Page 21: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Syncing HealthKit from the Apple WatchNashville CocoaHeads - HealthKit

• Takes a while • Use Watch Connectivity

to update iOS UI from HealthKit readings on the watch

Page 22: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

DEMO TIME GET ON THE BIKE

Page 23: DEVELOPING APPS WITH HEALTHKIT - LunarLincoln · WITH HEALTHKIT – Jonathan Wiley (@microchip128) 5.25.2016. INTRODUCING HealthKit. What is HealthKit? Nashville CocoaHeads - HealthKit.

Questions?

@LunarLincoln | www.LunarLincoln.com