❤️

HealthKit

iOS 8+

Apple's framework for health and fitness data management. HealthKit provides a central repository for health and fitness data, allowing apps to share and access health information with user permission.

Health & Fitness
Official Apple Documentation →
iOS Version Compatibility
99.7%
coverage

of iOS users worldwide can use HealthKit (iOS 8+ required)

iOS VersionMarket ShareStatus
iOS 18.730.3%Supported
iOS 18.629.8%Supported
iOS 26.110.7%Supported
iOS 18.56.0%Supported
iOS 16.72.3%Supported
iOS 26.22.0%Supported
iOS 18.31.8%Supported
iOS 15.81.8%Supported
iOS 11.01.7%Supported
iOS 17.61.7%Supported

Key Features

Store and query health data

Share data between health apps

Background delivery of health updates

Workout and activity tracking

Heart rate and vital signs monitoring

Integration with Apple Watch

Code Examples

Request HealthKit Authorization

Request permission to read and write health data

import HealthKit

class HealthKitManager {
    let healthStore = HKHealthStore()
    
    func requestAuthorization() {
        guard HKHealthStore.isHealthDataAvailable() else {
            print("HealthKit not available")
            return
        }
        
        let typesToRead: Set<HKObjectType> = [
            HKObjectType.quantityType(forIdentifier: .stepCount)!,
            HKObjectType.quantityType(forIdentifier: .heartRate)!
        ]
        
        let typesToWrite: Set<HKSampleType> = [
            HKObjectType.quantityType(forIdentifier: .stepCount)!
        ]
        
        healthStore.requestAuthorization(toShare: typesToWrite, read: typesToRead) { success, error in
            if success {
                print("HealthKit authorized")
            } else if let error = error {
                print("Error: \(error.localizedDescription)")
            }
        }
    }
}

Query Step Count

Retrieve step count data for today

import HealthKit

func queryStepCount(completion: @escaping (Double) -> Void) {
    guard let stepType = HKQuantityType.quantityType(forIdentifier: .stepCount) else { return }
    
    let now = Date()
    let startOfDay = Calendar.current.startOfDay(for: now)
    let predicate = HKQuery.predicateForSamples(withStart: startOfDay, end: now, options: .strictStartDate)
    
    let query = HKStatisticsQuery(quantityType: stepType, quantitySamplePredicate: predicate, options: .cumulativeSum) { _, result, error in
        guard let result = result, let sum = result.sumQuantity() else {
            completion(0)
            return
        }
        
        completion(sum.doubleValue(for: HKUnit.count()))
    }
    
    HKHealthStore().execute(query)
}

Frequently Asked Questions

What is HealthKit?

Apple's framework for health and fitness data management. HealthKit provides a central repository for health and fitness data, allowing apps to share and access health information with user permission.

Which iOS versions support HealthKit?

HealthKit is available on iOS 8 and later. Currently, 99.7% of iOS users worldwide can use this framework.

What are alternatives to HealthKit?

Related frameworks include Coremotion. Each has different capabilities and iOS version requirements.