AppleHealthAuthorizationProvider
Wrap the HealthKit screen with this provider to request access to selected HealthKit sample types. It can request access automatically or render the app-provided permission UI. Its children include the screen's health sync only after the provider's request flow is ready.
import { ActivityIndicator } from "react-native";
import { DataSync } from "@ovok/native/data-sync";
import { HKQuantityTypeIdentifier } from "@kingstinct/react-native-healthkit";
<DataSync.AppleHealthAuthorizationProvider
readIdentifiers={[HKQuantityTypeIdentifier.bodyMass]}
fallback={<ActivityIndicator />}
onAuthorizationStatusChange={setHealthKitStatus}
>
<DataSync.AppleHealthSync dataToSync={appleDataToSync} />
</DataSync.AppleHealthAuthorizationProvider>;
Props
| Prop | Required | Description |
|---|---|---|
readIdentifiers | Yes | HealthKit sample types the feature reads. |
writeIdentifiers | No | HealthKit sample types the app writes. Omit for read-only import. |
fallback | No | React content for the authorization wait/request states. |
renderManualRequestUI | No | Render callback receiving the provider's requestAccess function. Use together with skipRequest. |
skipRequest | No | Required when renderManualRequestUI is supplied. Set false to render your request UI; true bypasses the provider's request gate and renders children. |
onAuthorizationStatusChange | No | Receives an AppleHealthAuthorizationStatus update. |
When neither manual-request prop is supplied, the provider requests access automatically when HealthKit reports that a request should be made. The two manual props form a TypeScript discriminated union: provide both or omit both.
Status
AppleHealthAuthorizationStatus contains:
state:unknown,shouldRequest,requesting,ready, orerror;notRequestedReadIdentifiers: requested read types still awaiting an answer;notRequestedWriteIdentifiers: requested write types still awaiting an answer;- optional
errorwhen the request or status inspection fails.
HealthKit does not reveal whether a person denied read access to a type. A
ready state means the provider no longer has a request pending; it does not
prove every requested type is readable. Treat empty reads as a valid result.
The provider can filter read identifiers still reported as unanswered so one
unanswered type does not prevent syncing other configured types. Keep the
readIdentifiers aligned with the identifiers in dataToSync.
Native setup
Enable the HealthKit capability and add the app's
NSHealthShareUsageDescription. Add the write usage description and HealthKit
write setup only if the app writes to HealthKit. See
installation and native setup and the
HealthKit and Health Connect guide.