I’m writing a small series on HealthKit as we’re approaching the New Year and the release of the WATCH, especially the Sports edition. For understanding HealthKit units, take a look at my first post: HealthKit: Let’s Talk About Units. In this post, I’m going to talk about getting your user’s personal data.

HKHealthStore

The HKHealthStore class provides an interface for accessing and storing the user’s health data. Since this is what you’re using to read and write from the HealthKit database, it’s best to just create this once. I like to wrap by healthStore constant in a singleton, which I use to interface with HealthKit.

Requesting authorization will pop up this permission screen to the user:

Note that we can only request READ permission for characteristics. This is because it doesn’t make sense for multiple apps to re-write user’s data of birth for example. If the user wants to add their date of birth, they can only do so in the official Apple’s Health App! This is what happens when you try to request authorization for write this data:

Querying for User Characteristics

Once you have the permission from the user to get their characteristic data, it’s very easy to query for their date of birth, biological sex, and blood type: