Read health data
Check authorization, read raw samples, and read totals for a fixed set of health data types.
Check availability
Call status() to see whether Health is available on this device and the per-type authorization state before you read anything. Health can be switched off in a given app build — check bdk.capabilities.has("health.read") before showing any health UI.
When it isn't available, status() returns a reason:
Outside the app the command doesn't run: the returned object has no ok field and triggered: false. status()'s result is a union — check "ok" in result before reading envelope-only fields.
Request access
Ask for authorization to read health data. Pass types to request a subset, or omit it to request every type your app build enables.
On iOS, read authorization always reports unknown — HealthKit never reveals whether a read was granted or denied. A denied read looks exactly like an empty result, so treat an empty read as possibly-denied, not as "no data recorded".
Read totals
Use aggregate() for steps, distance, and active calories instead of summing raw samples yourself — it buckets and sums on the native side so you don't double-count across sources.
interval controls the bucket size: total, hour, day, or month. The result carries unit (the type's unit), stat (sum for quantity totals, avg for types like heart rate), and the buckets themselves.
Read raw samples
Read individual samples for a type over a date range when a total isn't enough — for example, plotting each heart-rate reading.
limit caps how many samples come back; check truncated to see if there are more than limit in range, and use startDate/endDate/ascending to page through them.
List enabled types
enabledTypes() returns the HealthTypeIds this app build enables — an empty array when Health is off. Use it to build a picker instead of hardcoding the full list.
aggregate() doesn't support sleep or workouts — they're session types, not summable quantities. Use read() to pull their raw samples instead.