Capacitor HealthKit Plugin
:heart: Capacitor plugin to retrieve data from HealthKit :heart:
This is a clone of the @perfood/capacitor-healthkit@next
with improvements.
Disclaimer : for now only some of the HK data base, in the future the retrieve base will be bigger !
Getting Started
Prerequisites
- Add HealthKit to your Xcode project (section signing & capabilities)

- ADD Privacy - Health Share Usage Description to your Xcode project
- ADD Privacy - Health Update Usage Description to your Xcode project
You can simply put this into the info.plist
file
<key>NSHealthShareUsageDescription</key>
<string>Read Health Data</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Read Health Data</string>
Installing
Do
npm i --save @codoffer/capacitor-healthkit
Then
npx cap update
API
requestAuthorization(...)
requestAuthorization(options: RequestAuthorizationOptions) => Promise<void>
Param | Type |
---|
options | RequestAuthorizationOptions |
isAvailable()
isAvailable() => Promise<void>
getAuthorizationStatus(...)
getAuthorizationStatus(options: GetAuthorizationStatusOptions) => Promise<{ status: AuthorizationStatus; }>
Param | Type |
---|
options | GetAuthorizationStatusOptions |
Returns: Promise<{ status: AuthorizationStatus; }>
getStatisticsCollection(...)
getStatisticsCollection(options: StatisticsCollectionOptions) => Promise<StatisticsCollectionOutput>
Param | Type |
---|
options | StatisticsCollectionOptions |
Returns: Promise<StatisticsCollectionOutput>
getBodyMassEntries(...)
getBodyMassEntries(options: BodyMassQueryOptions) => Promise<BodyMassQueryOutput>
Param | Type |
---|
options | BodyMassQueryOptions |
Returns: Promise<BodyMassQueryOutput>
getWorkouts(...)
getWorkouts(options: WorkoutsQueryOptions) => Promise<WorkoutsQueryOutput>
Param | Type |
---|
options | WorkoutsQueryOptions |
Returns: Promise<WorkoutsQueryOutput>
Interfaces
RequestAuthorizationOptions
Prop | Type |
---|
all | string[] |
read | string[] |
write | string[] |
GetAuthorizationStatusOptions
StatisticsCollectionOutput
Prop | Type |
---|
data | { startDate: string; endDate: string; value: number; }[] |
StatisticsCollectionOptions
Prop | Type |
---|
startDate | string |
endDate | string |
anchorDate | string |
interval | StatisticsCollectionQueryInterval |
quantityTypeSampleName | QuantityType |
StatisticsCollectionQueryInterval
Prop | Type |
---|
unit | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year' |
value | number |
BodyMassQueryOutput
Prop | Type |
---|
data | { date: string; value: number; unit: string; uuid: string; sourceName: string; sourceBundleId: string; }[] |
BodyMassQueryOptions
Prop | Type |
---|
startDate | string |
endDate | string |
limit | number |
WorkoutsQueryOutput
Prop | Type |
---|
data | { uuid: string; startDate: string; endDate: string; duration: number; device?: HealthKitDevice; source: string; sourceBundleId: string; workoutActivityType: string; workoutActivityTypeId: number; totalEnergyBurned?: number; totalDistance?: number; totalFlightsClimbed?: number; totalSwimmingStrokeCount?: number; }[] |
HealthKitDevice
Prop | Type |
---|
name | string |
model | string |
manufacturer | string |
hardwareVersion | string |
softwareVersion | string |
firmwareVersion | string |
localIdentifier | string |
udiDeviceIdentifier | string |
WorkoutsQueryOptions
Prop | Type |
---|
startDate | string |
endDate | string |
limit | number |
Type Aliases
AuthorizationStatus
'notDetermined' | 'sharingDenied' | 'sharingAuthorized'
QuantityType
'stepCount' | 'activeEnergyBurned' | 'appleExerciseTime' | 'basalEnergyBurned' | 'bloodGlucose' | 'distanceCycling' | 'distanceWalkingRunning' | 'flightsClimbed' | 'heartRate' | 'weight'