LimitedRound 2 is open. Get your first month free, no extra charge.Join the waitlist ›
Wire in your backend

How to add HealthKit to an iOS app

TL;DR. HealthKit gives an iOS app read and write access to health and fitness data from the Health app, like steps, heart rate, and sleep. You enable the HealthKit capability, add usage strings to Info.plist, request permission, and query an HKHealthStore. There are no keys to ship. AppFlight enables the capability and generates the queries.

What HealthKit does for an iOS app

HealthKit is the shared store behind the Health app, and it lets your app read data other apps and the Apple Watch write, or contribute its own. A fitness app might read step count and active energy, a sleep app might read sleep analysis, and a workout app might write completed sessions back. Access is granular: the user grants or denies each data type, and your app cannot tell whether a type was denied or simply has no data, which you handle gracefully. Because the data is sensitive, Apple holds HealthKit apps to stricter privacy rules than most.

Adding HealthKit with AppFlight

HealthKit needs the HealthKit capability plus usage description strings in Info.plist for the data you read and write. In AppFlight you enable HealthKit for the project, and because there is no key, nothing is classified as client or backend. AppFlight adds the NSHealthShareUsageDescription and NSHealthUpdateUsageDescription strings, which App Review reads, and you make sure they describe the real feature. You can then ask the AI to request permission for step count and query today's total, and it generates the SwiftUI and the HealthKit calls.

A SwiftUI example

Request read access, then sum today's step count with a modern statistics query:

import HealthKit

let store = HKHealthStore()

func requestAccess() async throws {
    let steps = HKQuantityType(.stepCount)
    try await store.requestAuthorization(toShare: [], read: [steps])
}

func stepsToday() async throws -> Double {
    let steps = HKQuantityType(.stepCount)
    let start = Calendar.current.startOfDay(for: Date())
    let predicate = HKQuery.predicateForSamples(withStart: start, end: Date())

    let descriptor = HKStatisticsQueryDescriptor(
        predicate: HKSamplePredicate.quantitySample(type: steps, predicate: predicate),
        options: .cumulativeSum
    )
    let result = try await descriptor.result(for: store)
    return result?.sumQuantity()?.doubleValue(for: .count()) ?? 0
}

Call requestAccess() before you query, and present the number in a view with @State. Guard for HKHealthStore.isHealthDataAvailable() since iPad does not support HealthKit.

Alternatives

There is no real substitute for reading Apple Health data: HealthKit is the only API for it. What varies is what you pair it with. SwiftData or Core Data store your app's own derived data, like goals and streaks, while HealthKit supplies the raw measurements. If you need health data on a server or across platforms, you export selected values through your own backend with the user's consent, rather than reaching for a different on-device framework.

FAQ

Does HealthKit need an API key?

No. HealthKit reads and writes data on device through the user Health database. There is no key or backend. You enable the HealthKit capability and add usage description strings, and the user grants or denies access per data type.

What does App Review require for HealthKit?

You must add clear NSHealthShareUsageDescription and NSHealthUpdateUsageDescription strings explaining why you read or write each type, and your use must match what the app actually does. Apple also restricts using Health data for advertising or selling it. Treat it as guidance and check the current guidelines.

Can I test HealthKit in the simulator?

Some of it. The simulator has a Health app you can seed with sample data, but certain types and live sensor data only behave correctly on a real device. Test core flows on hardware before submitting.

Sources

Build this app without opening Xcode.

AppFlight turns a plain-English prompt into a real native iOS app and ships it to the App Store. Round 2 is open: free for your first month.

Join the waitlist