Introduction to HealthKit: Reading Steps, Weight, Height, and More
An overview of the fundamental basics in the HealthKit API and some more complex examples to get you started.
Jul 22, 2016 • Kevin Hou
I was instructed to integrate HealthKit information — specifically pulling steps data — into Breathometer’s upcoming app. I’m realitively new to Swift having only started a month ago, so this project was a way for me to get more familiar with the language and IDE. My task was to pull the data from HealhtKit then populate a table within a page of the app. This data could then be used for visualizations, analysis, etc. Here are my main learning goals for this project:
Learn how to integrate with HealthKit and pull data from a “3rd party” source (not really a 3rd party but it's an API all the same)
Learn the fundamentals of table views, populating views, etc. so that I can develop a better understanding of Swift frontend (see next post)
Authorizing and Integrating with HealthKit
Nested within the authorizeHealthKit function:
Get Healthkit information to read
Healthkit information to write
To actually get data from healthkit, create a function within the class. This one, for example, gets your birthdate from health kit:
More complex example
Pulls steps from Healthkit (x number of days) and show it in a table view by creating a new function within the HealthKitManager class.
Returning steps by per day for x number of days: