HealthKit

HealthKit is a framework that is provided by apple that helps us in getting and managing user health-related data in a very easy and convenient way.

We can integrate HealthKit in any application just by a grant the application to get access to the HealthKit data. so, the user data was easily available to that application from the healthKit Database. The user itself decide which data user allow to access or not.

To Implement a health Kit in any application. We need to follow these steps :

  1. we need to add these two in info Plist.
  • Privacy – Health Share Usage Description
  • Privacy – Health Update Usage Description

we need to ask for permission from the user to access user HealthKit data. 

 

So, with the above code, we got permission from the user to fetch steps. And that type of view appears on the screen 

We need to enable that permission of steps as shown in the above View.

3 . When the user got the permission we are here actually fetch the steps of the user.

We can get a Date by calling that above function like this :

These will give us the heartRate from startDate to endDate.

Steps: Optional(300.0)..

This is how we can calculate the steps through the healthKit. We can also calculate the heartRate, calories, and other elements through healthKit.

Kudos!

Leave a Reply