Environment: iPhone 13 Pro, iOS 26.5. Affects a single user out of many; cannot reproduce on any of our test devices.
We use HKStatisticsCollectionQuery to read step counts for a statistics screen. For one specific user, the query’s initialResultsHandler appears to deliver results == nil (the success branch never runs), so our completion is never called and the screen shows an infinite spinner.
func getDayHourlySteps(currentDay: Date, completion: @escaping ([HKStatistics]) -> Void) {
let anchorComponents = Calendar.current.dateComponents([.day, .month, .year, .hour], from: currentDay)
let anchorDate = Calendar.current.date(from: anchorComponents)!
var interval = DateComponents(); interval.hour = 1
let manualPredicate = NSPredicate(format: "metadata.%K != YES", HKMetadataKeyWasUserEntered)
let query = HKStatisticsCollectionQuery(
quantityType: HKQuantityType.quantityType(forIdentifier: .stepCount)!,
quantitySamplePredicate: manualPredicate,
options: .cumulativeSum,
anchorDate: anchorDate,
intervalComponents: interval
)
query.initialResultsHandler = { _, results, error in
guard let results else {
// For the affected user we suspect we land here (results == nil).
// What HKError shows up here? (we are adding logging now)
return
}
// ...enumerate & completion...
}
healthStore.execute(query)
}
What we’ve confirmed / ruled out:
-
Read authorization for
stepCountis granted (the user toggled it ON in the HealthKit sheet on video). -
The Apple Health app shows step data for this user (so data exists).
-
A coarser query (2-year interval) for the same user succeeds, while the hourly query appears to fail — same type / predicate / options / auth.
-
Symptom persists across app reinstall and device reboot, and re-granting Health permission.
-
Permission denial returns empty results (per Apple docs), not an error — so this isn’t simple denial.
-
Not
errorDatabaseInaccessibleas far as we can tell (foreground, device unlocked).
Questions:
-
What can cause
HKStatisticsCollectionQuery.initialResultsHandlerto returnresults == nil(with an error) persistently for one device/account, when read auth is granted and data exists? -
Can
errorHealthDataRestrictedoccur without an MDM/supervised profile (i.e., on a normal consumer device)? What device/account states actually trigger it? -
Is it expected that a coarse-interval query succeeds while an hourly-interval query on the same type fails for the same user?
We’re adding logging of the actual HKError code + authorizationStatus for the next occurrence, but would appreciate any insight on what conditions produce this.
