Hello,
We received a customer report about intermittent missing historical step-count data when using HKStatisticsCollectionQuery on iOS 27 beta.
When the query was executed on August 16, only the most recent two days—August 16 and August 15—returned correct step counts. Earlier dates returned nil from sumQuantity() and were consequently treated as zero.
However, queries executed on August 14 and August 18 returned the expected data. Therefore, the problem appears to be intermittent rather than consistently reproducible.
The customer confirmed that all affected historical step counts were visible in the Apple Health app, including the dates returned as zero by our query.
We have not received the same type of customer report from devices running iOS 26 or earlier.
Here is a simplified version of our query:
guard let stepType = HKObjectType.quantityType(
forIdentifier: .stepCount
) else {
return
}
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(identifier: "Asia/Seoul")!
let queryStartDate = calendar.startOfDay(for: parsedStartDate)
let tomorrow = calendar.date(byAdding: .day, value: 1, to: Date())!
let queryEndDate = calendar.startOfDay(for: tomorrow)
let datePredicate = HKQuery.predicateForSamples(
withStart: queryStartDate,
end: queryEndDate,
options: .strictStartDate
)
let nonUserEnteredPredicate = HKQuery.predicateForObjects(
withMetadataKey: HKMetadataKeyWasUserEntered,
operatorType: .notEqualTo,
value: NSNumber(value: true)
)
let predicate = NSCompoundPredicate(
andPredicateWithSubpredicates: [
datePredicate,
nonUserEnteredPredicate
]
)
let anchorDate = calendar.startOfDay(for: Date())
var interval = DateComponents()
interval.day = 1
let query = HKStatisticsCollectionQuery(
quantityType: stepType,
quantitySamplePredicate: predicate,
options: .cumulativeSum,
anchorDate: anchorDate,
intervalComponents: interval
)
query.initialResultsHandler = { _, results, error in
guard let results, error == nil else {
print("Query error: \(String(describing: error))")
return
}
results.enumerateStatistics(
from: queryStartDate,
to: queryEndDate
) { statistics, _ in
let steps = statistics
.sumQuantity()?
.doubleValue(for: .count()) ?? 0
print(statistics.startDate, statistics.endDate, steps)
}
}
healthStore.execute(query)
Observed behavior
Query executed on August 14: historical step counts returned correctly
Query executed on August 16:
August 16 and August 15 returned correctly
August 14 and earlier returned nil from sumQuantity()
Query executed on August 18: historical step counts returned correctly again
No query error was reported
All step counts remained visible in the customer's Apple Health app
Expected behavior
The query should consistently return cumulative daily step counts when matching HealthKit samples exist and are visible in the Health app.
Because this was reported through customer support, we do not currently know the exact iOS 27 beta build number. We are also unable to reproduce it consistently on our own test devices.
Questions
Is there a known intermittent issue with historical .stepCount queries on iOS 27 beta?
Can HealthKit temporarily return incomplete statistics while data is being indexed, synchronized, or migrated?
Is there a recommended way to detect that the returned statistics are temporarily incomplete?
Should applications retry the query when older statistics unexpectedly return nil without an error?
We have not received reports of this behavior from customers using iOS 26 or earlier.
Thank you.