Engineering

Integrating Apple HealthKit: The Right Way

Stop asking for all permissions on launch. How to build trust and sync data reliably.

HealthKit is a privilege, not a right. Apple will reject your app if you request access to health data without a clear, user-facing reason.

Permission Strategy

Never show the HealthKit permission modal on the first screen. Wait until the user performs an action that requires it—like finishing their first workout or opening the 'Stats' tab.

Writing Workouts (HKWorkout)

When you save a workout, you aren't just saving a string. You need to provide:

  • HKWorkoutActivityType (e.g., traditionalStrengthTraining)
  • Start and End dates (precise to the second)
  • Total Energy Burned (calculated or sampled)
  • Total Flight of Stairs or Distance (if applicable)

If your app crashes during a workout and loses the start time, you cannot write an accurate HealthKit entry. Always persist workout state locally (SQLite/UserDefaults) after every set.