Skip to content
All journal articles
Tutorials

HealthKit Integration

Implementing bi-directional Apple Health app data syncing for workouts, step counts, and active calories.

HealthKit enables applications to write and read health metrics safely under the strict control of user permissions.

Requesting Health Permissions

Before querying records, you must request permission in your plist and programmatically trigger the authorization sheet:

import HealthKit

let healthStore = HKHealthStore()

func requestAccess() {
    let shareTypes: Set<HKSampleType> = [
        HKObjectType.workoutType(),
        HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)!
    ]
    let readTypes: Set<HKObjectType> = [
        HKQuantityType.quantityType(forIdentifier: .stepCount)!
    ]
    
    healthStore.requestAuthorization(toShare: shareTypes, read: readTypes) { success, error in
        if success {
            print("Access to HealthKit data approved.")
        }
    }
}
Continue exploring the journal
GOOD THINGS START WITH A CONVERSATION

Let’s make
something matter.

Your ambition. Our attention to detail.
A website you’re proud to put your name on.

Tell us about your project hello@nanhuinteractive.dev