Read health data
HealthBridge returns HealthDataReadResult with typed HealthDataSample
subclasses where the public API supports them.
Query a type
Section titled “Query a type”var query = new HealthDataQuery( "steps", daysBack: 7, maxRecords: 100);
HealthDataReadResult result = await HealthBridgeService.ReadDataAsync(query);
if (!result.Success){ // Show a recoverable error. return;}
foreach (HealthDataSample sample in result.Samples){ if (sample is StepsSample steps) { long count = steps.Count; // Update a transient view model. }}Queries clamp daysBack to 1–90 and maxRecords to at least one.
Typed and generic samples
Section titled “Typed and generic samples”Prefer typed models such as:
StepsSampleSleepSampleWeightSampleCaloriesSampleDistanceSampleNutritionSampleHydrationSample
For another registry-backed type, use GetValue<T>(key) on the base sample.
There is no universal Value property.
Inspect runtime type capability
Section titled “Inspect runtime type capability”Registry metadata describes the SDK surface; active-device capability describes what can safely run now. Before rendering a picker row or issuing a query, ask the service for the selected ID:
HealthDataTypeCapability capability = HealthBridgeService.GetDataTypeCapability(selectedId);
if (!capability.CanRead){ // Keep the row disabled and present capability.Reason. return;}
HealthDataReadResult result = await HealthBridgeService.ReadDataAsync( new HealthDataQuery(selectedId, daysBack: 7, maxRecords: 100));Use HealthBridgeService.GetDataTypeCapabilities() to build a complete picker.
Exclude PermissionOnly rows from data selection. Read-only rows remain
selectable for reads; unavailable and deprecated rows stay visible but disabled
with their capability reason.
For a supported registry row without a dedicated typed model, render the field
schema from capability.Type.GetFields(capability.Platform) and read values
from HealthDataSample.Values. Do not hard-code a stale list of types or assume
that every generic sample has one numeric value.
Empty and partial results
Section titled “Empty and partial results”Success=false: show a recoverable error state.- Successful empty result: show a normal empty state.
- Missing generic value: keep it unavailable.
- iOS empty result: do not infer permission or absence of records.
