Skip to content
Introducing AI Conversations: Natural Language Interaction for Your Apps! Learn More

Writing Data

You can write health data to Apple HealthKit and Android Health Connect using the Write method. Request write permissions first using PermissionType.Write.

public class HealthWriteViewModel(IHealthService health)
{
async Task WriteDataAsync()
{
// 1. Request write permissions (uniform for all types)
await health.RequestPermissions(
PermissionType.Write,
DataType.Weight,
DataType.StepCount,
DataType.Hydration
);
// Or mix read/write per metric in a single call
// await health.RequestPermissions(
// (PermissionType.Write, DataType.Weight),
// (PermissionType.Write, DataType.StepCount),
// (PermissionType.ReadWrite, DataType.Hydration)
// );
var now = DateTimeOffset.Now;
// 2. Write a weight measurement
await health.Write(new NumericHealthResult(DataType.Weight, now, now, 75.0));
// 3. Write step counts over a time range
await health.Write(new NumericHealthResult(
DataType.StepCount, now.AddMinutes(-30), now, 500
));
// 4. Write blood pressure
await health.Write(new BloodPressureResult(now, now, 120.0, 80.0));
}
}