A HealthKit demo asks permission and reads steps. A production pipeline must handle partial authorization, revised samples, multiple sources, timezones, deletion, and interrupted synchronization.
Treat authorization per data type. HealthKit intentionally limits what an app can infer about denied read access, so UI states should avoid claiming more certainty than the API provides.
Anchored queries return changes since a durable anchor. Save the new anchor only after changes are committed locally. If processing fails, reuse the old anchor and let stable sample identities make replay safe.
Do not sum every source blindly. A watch and phone can represent overlapping activity. Use HealthKit statistics queries and source-aware policies appropriate to the metric.
Daily aggregation requires the user's calendar and timezone. A UTC boundary can split one local night or workout across dates.
Preserve enough source metadata to explain imported data and prevent writing an app-created sample back as a duplicate import. Tag HealthKit writes with application metadata.
Separate source events from daily snapshots. Events retain traceability; snapshots make UI and backend synchronization efficient.
Test timezone changes, daylight-saving transitions, deleted samples, repeated anchored pages, and multiple devices. HealthKit supplies records, but the application defines their stable meaning.