@DTS Engineer
In my iOS app, I query HealthKit step count using HKStatisticsCollectionQueryDescriptor with .cumulativeSum. I’m seeing a reproducible issue where daily aggregation returns an empty HKStatisticsCollection for recent step-count data, while hourly aggregation for the same date range can return valid data, and HKSampleQuery can also retrieve the underlying step samples.
This does not appear to be an authorization issue, because other HealthKit data types are available and step samples can be read. It also does not appear to be a time zone boundary issue: the device time zone is Asia/Shanghai (UTC+8), and the queried date ranges are local-day ranges such as 2026-06-14 00:00:00 to 2026-06-14 23:59:59.
Observed behavior:
- HKStatisticsCollectionQueryDescriptor for stepCount, intervalComponents = DateComponents(day: 1), returns 0 buckets / 0 total steps.
- HKStatisticsCollectionQueryDescriptor for stepCount, intervalComponents = DateComponents(hour: 1), can return valid hourly buckets for some dates in the same period.
- HKSampleQuery for stepCount can retrieve raw step samples for dates where the daily statistics query returns empty.
- No error is thrown by descriptor.result(for:). The query succeeds but returns an empty statistics collection.
Expected behavior:
Daily cumulative step-count statistics should include buckets for days that contain step samples, or at least be consistent with the hourly aggregation and raw samples for the same date range.
Example logs:
[HealthKitSteps] daily statistics result range=2026-06-14 00:00:00...2026-06-14 23:59:59 interval=1d buckets=0 valuedBuckets=0 total=0
[HealthKitSteps] daily statistics result range=2026-06-13 00:00:00...2026-06-13 23:59:59 interval=1d buckets=0 valuedBuckets=0 total=0
[HealthKitSteps] hourly statistics result range=2026-06-09 00:00:00...2026-06-09 23:59:59 interval=1h buckets=9 valuedBuckets=9 total=3379
[HealthKitSteps] hourly statistics result range=2026-06-08 00:00:00...2026-06-08 23:59:59 interval=1h buckets=3 valuedBuckets=3 total=6216
Query details:
- Quantity type: HKQuantityTypeIdentifier.stepCount
- Statistics option: .cumulativeSum
- Daily query interval: DateComponents(day: 1)
- Hourly query interval: DateComponents(hour: 1)
- Predicate: HKQuery.predicateForSamples(withStart: startOfLocalDay, end: endOfLocalDay, options: .strictStartDate)
- Anchor date: startOfLocalDay
- Device time zone: Asia/Shanghai (UTC+8)