iOS apps and more

Earliest sample dates in HealthKit

03 Jun 2020

When building a watchOS extension for my iPhone app Personal Best, I couldn’t figure out why querying the HealthKit store for workouts was only returning 25 results, as opposed to over 700 on iPhone.

It turns out that iOS and watchOS have separate HealthKit stores. watchOS only stores seven days worth of workouts.

You can confirm this by using HKHealthStore’s earliestPermittedSampleDate method:

let healthStore = HKHealthStore()

// When called on iOS:
healthStore.earliestPermittedSampleDate() // 0001-01-01 00:00:00 +0000

// When called on watchOS:
healthStore.earliestPermittedSampleDate() // 2020-05-25 23:00:00 +0000