@capgo/capacitor-health 8.3.1 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -23
- package/android/src/main/java/app/capgo/plugin/health/HealthManager.kt +5 -1
- package/dist/docs.json +14 -0
- package/dist/esm/definitions.d.ts +4 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/HealthPlugin/Health.swift +15 -18
- package/ios/Sources/HealthPlugin/HealthPlugin.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -546,18 +546,19 @@ Supported on iOS (HealthKit) and Android (Health Connect).
|
|
|
546
546
|
|
|
547
547
|
#### HealthSample
|
|
548
548
|
|
|
549
|
-
| Prop | Type | Description
|
|
550
|
-
| ---------------- | --------------------------------------------------------- |
|
|
551
|
-
| **`dataType`** | <code><a href="#healthdatatype">HealthDataType</a></code> |
|
|
552
|
-
| **`value`** | <code>number</code> |
|
|
553
|
-
| **`unit`** | <code><a href="#healthunit">HealthUnit</a></code> |
|
|
554
|
-
| **`startDate`** | <code>string</code> |
|
|
555
|
-
| **`endDate`** | <code>string</code> |
|
|
556
|
-
| **`sourceName`** | <code>string</code> |
|
|
557
|
-
| **`sourceId`** | <code>string</code> |
|
|
558
|
-
| **`
|
|
559
|
-
| **`
|
|
560
|
-
| **`
|
|
549
|
+
| Prop | Type | Description |
|
|
550
|
+
| ---------------- | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
551
|
+
| **`dataType`** | <code><a href="#healthdatatype">HealthDataType</a></code> | |
|
|
552
|
+
| **`value`** | <code>number</code> | |
|
|
553
|
+
| **`unit`** | <code><a href="#healthunit">HealthUnit</a></code> | |
|
|
554
|
+
| **`startDate`** | <code>string</code> | |
|
|
555
|
+
| **`endDate`** | <code>string</code> | |
|
|
556
|
+
| **`sourceName`** | <code>string</code> | |
|
|
557
|
+
| **`sourceId`** | <code>string</code> | |
|
|
558
|
+
| **`platformId`** | <code>string</code> | Platform-specific unique identifier (HealthKit UUID on iOS, Health Connect metadata ID on Android). |
|
|
559
|
+
| **`sleepState`** | <code><a href="#sleepstate">SleepState</a></code> | For sleep data, indicates the sleep state (e.g., 'asleep', 'awake', 'rem', 'deep', 'light'). |
|
|
560
|
+
| **`systolic`** | <code>number</code> | For blood pressure data, the systolic value in mmHg. |
|
|
561
|
+
| **`diastolic`** | <code>number</code> | For blood pressure data, the diastolic value in mmHg. |
|
|
561
562
|
|
|
562
563
|
|
|
563
564
|
#### QueryOptions
|
|
@@ -595,17 +596,18 @@ Supported on iOS (HealthKit) and Android (Health Connect).
|
|
|
595
596
|
|
|
596
597
|
#### Workout
|
|
597
598
|
|
|
598
|
-
| Prop | Type | Description
|
|
599
|
-
| ----------------------- | --------------------------------------------------------------- |
|
|
600
|
-
| **`workoutType`** | <code><a href="#workouttype">WorkoutType</a></code> | The type of workout.
|
|
601
|
-
| **`duration`** | <code>number</code> | Duration of the workout in seconds.
|
|
602
|
-
| **`totalEnergyBurned`** | <code>number</code> | Total energy burned in kilocalories (if available).
|
|
603
|
-
| **`totalDistance`** | <code>number</code> | Total distance in meters (if available).
|
|
604
|
-
| **`startDate`** | <code>string</code> | ISO 8601 start date of the workout.
|
|
605
|
-
| **`endDate`** | <code>string</code> | ISO 8601 end date of the workout.
|
|
606
|
-
| **`sourceName`** | <code>string</code> | Source name that recorded the workout.
|
|
607
|
-
| **`sourceId`** | <code>string</code> | Source bundle identifier.
|
|
608
|
-
| **`
|
|
599
|
+
| Prop | Type | Description |
|
|
600
|
+
| ----------------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
601
|
+
| **`workoutType`** | <code><a href="#workouttype">WorkoutType</a></code> | The type of workout. |
|
|
602
|
+
| **`duration`** | <code>number</code> | Duration of the workout in seconds. |
|
|
603
|
+
| **`totalEnergyBurned`** | <code>number</code> | Total energy burned in kilocalories (if available). |
|
|
604
|
+
| **`totalDistance`** | <code>number</code> | Total distance in meters (if available). |
|
|
605
|
+
| **`startDate`** | <code>string</code> | ISO 8601 start date of the workout. |
|
|
606
|
+
| **`endDate`** | <code>string</code> | ISO 8601 end date of the workout. |
|
|
607
|
+
| **`sourceName`** | <code>string</code> | Source name that recorded the workout. |
|
|
608
|
+
| **`sourceId`** | <code>string</code> | Source bundle identifier. |
|
|
609
|
+
| **`platformId`** | <code>string</code> | Platform-specific unique identifier (HealthKit UUID on iOS, Health Connect metadata ID on Android). |
|
|
610
|
+
| **`metadata`** | <code><a href="#record">Record</a><string, string></code> | Additional metadata (if available). |
|
|
609
611
|
|
|
610
612
|
|
|
611
613
|
#### QueryWorkoutsOptions
|
|
@@ -636,6 +636,8 @@ class HealthManager {
|
|
|
636
636
|
}
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
+
payload.put("platformId", metadata.id)
|
|
640
|
+
|
|
639
641
|
return payload
|
|
640
642
|
}
|
|
641
643
|
|
|
@@ -912,9 +914,11 @@ class HealthManager {
|
|
|
912
914
|
}
|
|
913
915
|
}
|
|
914
916
|
|
|
917
|
+
payload.put("platformId", session.metadata.id)
|
|
918
|
+
|
|
915
919
|
// Note: customMetadata is not available on Metadata in Health Connect
|
|
916
920
|
// Metadata only contains dataOrigin, device, and lastModifiedTime
|
|
917
|
-
|
|
921
|
+
|
|
918
922
|
return payload
|
|
919
923
|
}
|
|
920
924
|
|
package/dist/docs.json
CHANGED
|
@@ -389,6 +389,13 @@
|
|
|
389
389
|
"complexTypes": [],
|
|
390
390
|
"type": "string | undefined"
|
|
391
391
|
},
|
|
392
|
+
{
|
|
393
|
+
"name": "platformId",
|
|
394
|
+
"tags": [],
|
|
395
|
+
"docs": "Platform-specific unique identifier (HealthKit UUID on iOS, Health Connect metadata ID on Android).",
|
|
396
|
+
"complexTypes": [],
|
|
397
|
+
"type": "string | undefined"
|
|
398
|
+
},
|
|
392
399
|
{
|
|
393
400
|
"name": "sleepState",
|
|
394
401
|
"tags": [],
|
|
@@ -621,6 +628,13 @@
|
|
|
621
628
|
"complexTypes": [],
|
|
622
629
|
"type": "string | undefined"
|
|
623
630
|
},
|
|
631
|
+
{
|
|
632
|
+
"name": "platformId",
|
|
633
|
+
"tags": [],
|
|
634
|
+
"docs": "Platform-specific unique identifier (HealthKit UUID on iOS, Health Connect metadata ID on Android).",
|
|
635
|
+
"complexTypes": [],
|
|
636
|
+
"type": "string | undefined"
|
|
637
|
+
},
|
|
624
638
|
{
|
|
625
639
|
"name": "metadata",
|
|
626
640
|
"tags": [],
|
|
@@ -39,6 +39,8 @@ export interface HealthSample {
|
|
|
39
39
|
endDate: string;
|
|
40
40
|
sourceName?: string;
|
|
41
41
|
sourceId?: string;
|
|
42
|
+
/** Platform-specific unique identifier (HealthKit UUID on iOS, Health Connect metadata ID on Android). */
|
|
43
|
+
platformId?: string;
|
|
42
44
|
/** For sleep data, indicates the sleep state (e.g., 'asleep', 'awake', 'rem', 'deep', 'light'). */
|
|
43
45
|
sleepState?: SleepState;
|
|
44
46
|
/** For blood pressure data, the systolic value in mmHg. */
|
|
@@ -86,6 +88,8 @@ export interface Workout {
|
|
|
86
88
|
sourceName?: string;
|
|
87
89
|
/** Source bundle identifier. */
|
|
88
90
|
sourceId?: string;
|
|
91
|
+
/** Platform-specific unique identifier (HealthKit UUID on iOS, Health Connect metadata ID on Android). */
|
|
92
|
+
platformId?: string;
|
|
89
93
|
/** Additional metadata (if available). */
|
|
90
94
|
metadata?: Record<string, string>;
|
|
91
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type HealthDataType =\n | 'steps'\n | 'distance'\n | 'calories'\n | 'heartRate'\n | 'weight'\n | 'sleep'\n | 'respiratoryRate'\n | 'oxygenSaturation'\n | 'restingHeartRate'\n | 'heartRateVariability'\n | 'bloodPressure'\n | 'bloodGlucose'\n | 'bodyTemperature'\n | 'height'\n | 'flightsClimbed'\n | 'exerciseTime'\n | 'distanceCycling'\n | 'bodyFat'\n | 'basalBodyTemperature'\n | 'basalCalories'\n | 'totalCalories'\n | 'mindfulness';\n\nexport type HealthUnit =\n | 'count'\n | 'meter'\n | 'kilocalorie'\n | 'bpm'\n | 'kilogram'\n | 'minute'\n | 'percent'\n | 'millisecond'\n | 'mmHg'\n | 'mg/dL'\n | 'celsius'\n | 'fahrenheit'\n | 'centimeter';\n\nexport interface AuthorizationOptions {\n /** Data types that should be readable after authorization. */\n read?: HealthDataType[];\n /** Data types that should be writable after authorization. */\n write?: HealthDataType[];\n}\n\nexport interface AuthorizationStatus {\n readAuthorized: HealthDataType[];\n readDenied: HealthDataType[];\n writeAuthorized: HealthDataType[];\n writeDenied: HealthDataType[];\n}\n\nexport interface AvailabilityResult {\n available: boolean;\n /** Platform specific details (for debugging/diagnostics). */\n platform?: 'ios' | 'android' | 'web';\n reason?: string;\n}\n\nexport interface QueryOptions {\n /** The type of data to retrieve from the health store. */\n dataType: HealthDataType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Maximum number of samples to return (defaults to 100). */\n limit?: number;\n /** Return results sorted ascending by start date (defaults to false). */\n ascending?: boolean;\n}\n\nexport type SleepState = 'inBed' | 'asleep' | 'awake' | 'rem' | 'deep' | 'light';\n\nexport interface HealthSample {\n dataType: HealthDataType;\n value: number;\n unit: HealthUnit;\n startDate: string;\n endDate: string;\n sourceName?: string;\n sourceId?: string;\n /** For sleep data, indicates the sleep state (e.g., 'asleep', 'awake', 'rem', 'deep', 'light'). */\n sleepState?: SleepState;\n /** For blood pressure data, the systolic value in mmHg. */\n systolic?: number;\n /** For blood pressure data, the diastolic value in mmHg. */\n diastolic?: number;\n}\n\nexport interface ReadSamplesResult {\n samples: HealthSample[];\n}\n\nexport type WorkoutType =\n // Common types (supported on both platforms)\n | 'americanFootball'\n | 'australianFootball'\n | 'badminton'\n | 'baseball'\n | 'basketball'\n | 'bowling'\n | 'boxing'\n | 'climbing'\n | 'cricket'\n | 'crossTraining'\n | 'curling'\n | 'cycling'\n | 'dance'\n | 'elliptical'\n | 'fencing'\n | 'functionalStrengthTraining'\n | 'golf'\n | 'gymnastics'\n | 'handball'\n | 'hiking'\n | 'hockey'\n | 'jumpRope'\n | 'kickboxing'\n | 'lacrosse'\n | 'martialArts'\n | 'pilates'\n | 'racquetball'\n | 'rowing'\n | 'rugby'\n | 'running'\n | 'sailing'\n | 'skatingSports'\n | 'skiing'\n | 'snowboarding'\n | 'soccer'\n | 'softball'\n | 'squash'\n | 'stairClimbing'\n | 'strengthTraining'\n | 'surfing'\n | 'swimming'\n | 'swimmingPool'\n | 'swimmingOpenWater'\n | 'tableTennis'\n | 'tennis'\n | 'trackAndField'\n | 'traditionalStrengthTraining'\n | 'volleyball'\n | 'walking'\n | 'waterFitness'\n | 'waterPolo'\n | 'waterSports'\n | 'weightlifting'\n | 'wheelchair'\n | 'yoga'\n // iOS specific types\n | 'archery'\n | 'barre'\n | 'cooldown'\n | 'coreTraining'\n | 'crossCountrySkiing'\n | 'discSports'\n | 'downhillSkiing'\n | 'equestrianSports'\n | 'fishing'\n | 'fitnessGaming'\n | 'flexibility'\n | 'handCycling'\n | 'highIntensityIntervalTraining'\n | 'hunting'\n | 'mindAndBody'\n | 'mixedCardio'\n | 'paddleSports'\n | 'pickleball'\n | 'play'\n | 'preparationAndRecovery'\n | 'snowSports'\n | 'stairs'\n | 'stepTraining'\n | 'surfingSports'\n | 'taiChi'\n | 'transition'\n | 'underwaterDiving'\n | 'wheelchairRunPace'\n | 'wheelchairWalkPace'\n | 'wrestling'\n | 'cardioDance'\n | 'socialDance'\n // Android specific types\n | 'backExtension'\n | 'barbellShoulderPress'\n | 'benchPress'\n | 'benchSitUp'\n | 'bikingStationary'\n | 'bootCamp'\n | 'burpee'\n | 'calisthenics'\n | 'crunch'\n | 'dancing'\n | 'deadlift'\n | 'dumbbellCurlLeftArm'\n | 'dumbbellCurlRightArm'\n | 'dumbbellFrontRaise'\n | 'dumbbellLateralRaise'\n | 'dumbbellTricepsExtensionLeftArm'\n | 'dumbbellTricepsExtensionRightArm'\n | 'dumbbellTricepsExtensionTwoArm'\n | 'exerciseClass'\n | 'forwardTwist'\n | 'frisbeedisc'\n | 'guidedBreathing'\n | 'iceHockey'\n | 'iceSkating'\n | 'jumpingJack'\n | 'latPullDown'\n | 'lunge'\n | 'meditation'\n | 'paddling'\n | 'paraGliding'\n | 'plank'\n | 'rockClimbing'\n | 'rollerHockey'\n | 'rowingMachine'\n | 'runningTreadmill'\n | 'scubaDiving'\n | 'skating'\n | 'snowshoeing'\n | 'stairClimbingMachine'\n | 'stretching'\n | 'upperTwist'\n | 'other';\n\nexport interface QueryWorkoutsOptions {\n /** Optional workout type filter. If omitted, all workout types are returned. */\n workoutType?: WorkoutType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Maximum number of workouts to return (defaults to 100). */\n limit?: number;\n /** Return results sorted ascending by start date (defaults to false). */\n ascending?: boolean;\n /**\n * Anchor for pagination. Use the anchor returned from a previous query to continue from that point.\n * On iOS, this is the ISO 8601 cursor returned by the previous query. On Android, this uses\n * Health Connect's pageToken.\n * Omit this parameter to start from the beginning.\n */\n anchor?: string;\n}\n\nexport interface Workout {\n /** The type of workout. */\n workoutType: WorkoutType;\n /** Duration of the workout in seconds. */\n duration: number;\n /** Total energy burned in kilocalories (if available). */\n totalEnergyBurned?: number;\n /** Total distance in meters (if available). */\n totalDistance?: number;\n /** ISO 8601 start date of the workout. */\n startDate: string;\n /** ISO 8601 end date of the workout. */\n endDate: string;\n /** Source name that recorded the workout. */\n sourceName?: string;\n /** Source bundle identifier. */\n sourceId?: string;\n /** Additional metadata (if available). */\n metadata?: Record<string, string>;\n}\n\nexport interface QueryWorkoutsResult {\n workouts: Workout[];\n /**\n * Anchor for the next page of results. Pass this value as the anchor parameter in the next query\n * to continue pagination. If undefined or null, there are no more results.\n */\n anchor?: string;\n}\n\nexport interface WriteSampleOptions {\n dataType: HealthDataType;\n value: number;\n /**\n * Optional unit override. If omitted, the default unit for the data type is used\n * (count for `steps`, meter for `distance`, kilocalorie for `calories`, bpm for `heartRate`, kilogram for `weight`).\n */\n unit?: HealthUnit;\n /** ISO 8601 start date for the sample. Defaults to now. */\n startDate?: string;\n /** ISO 8601 end date for the sample. Defaults to startDate. */\n endDate?: string;\n /** Metadata key-value pairs forwarded to the native APIs where supported. */\n metadata?: Record<string, string>;\n /** For blood pressure data, the systolic value in mmHg. Required when dataType is 'bloodPressure'. */\n systolic?: number;\n /** For blood pressure data, the diastolic value in mmHg. Required when dataType is 'bloodPressure'. */\n diastolic?: number;\n}\n\nexport type BucketType = 'hour' | 'day' | 'week' | 'month';\n\nexport type AggregationType = 'sum' | 'average' | 'min' | 'max';\n\nexport interface QueryAggregatedOptions {\n /** The type of data to aggregate from the health store. */\n dataType: HealthDataType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Time bucket for aggregation (defaults to 'day'). */\n bucket?: BucketType;\n /** Aggregation operation to perform (defaults to 'sum'). */\n aggregation?: AggregationType;\n}\n\nexport interface AggregatedSample {\n /** ISO 8601 start date of the bucket. */\n startDate: string;\n /** ISO 8601 end date of the bucket. */\n endDate: string;\n /** Aggregated value for the bucket. */\n value: number;\n /** Unit of the aggregated value. */\n unit: HealthUnit;\n}\n\nexport interface QueryAggregatedResult {\n samples: AggregatedSample[];\n}\n\nexport interface HealthPlugin {\n /** Returns whether the current platform supports the native health SDK. */\n isAvailable(): Promise<AvailabilityResult>;\n /** Requests read/write access to the provided data types. */\n requestAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;\n /** Checks authorization status for the provided data types without prompting the user. */\n checkAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;\n /** Reads samples for the given data type within the specified time frame. */\n readSamples(options: QueryOptions): Promise<ReadSamplesResult>;\n /** Writes a single sample to the native health store. */\n saveSample(options: WriteSampleOptions): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ version: string }>} a Promise with version for this device\n * @throws An error if something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n\n /**\n * Opens the Health Connect settings screen (Android only).\n * On iOS, this method does nothing.\n *\n * Use this to direct users to manage their Health Connect permissions\n * or to install Health Connect if not available.\n *\n * @throws An error if Health Connect settings cannot be opened\n */\n openHealthConnectSettings(): Promise<void>;\n\n /**\n * Shows the app's privacy policy for Health Connect (Android only).\n * On iOS, this method does nothing.\n *\n * This displays the same privacy policy screen that Health Connect shows\n * when the user taps \"Privacy policy\" in the permissions dialog.\n *\n * The privacy policy URL can be configured by adding a string resource\n * named \"health_connect_privacy_policy_url\" in your app's strings.xml,\n * or by placing an HTML file at www/privacypolicy.html in your assets.\n *\n * @throws An error if the privacy policy cannot be displayed\n */\n showPrivacyPolicy(): Promise<void>;\n\n /**\n * Queries workout sessions from the native health store.\n * Supported on iOS (HealthKit) and Android (Health Connect).\n *\n * @param options Query options including optional workout type filter, date range, limit, and sort order\n * @returns A promise that resolves with the workout sessions\n * @throws An error if something went wrong\n */\n queryWorkouts(options: QueryWorkoutsOptions): Promise<QueryWorkoutsResult>;\n\n /**\n * Queries aggregated health data from the native health store.\n * Aggregates data into time buckets (hour, day, week, month) with operations like sum, average, min, or max.\n * This is more efficient than fetching individual samples for large date ranges.\n *\n * Supported on iOS (HealthKit) and Android (Health Connect).\n *\n * @param options Query options including data type, date range, bucket size, and aggregation type\n * @returns A promise that resolves with the aggregated samples\n * @throws An error if something went wrong\n */\n queryAggregated(options: QueryAggregatedOptions): Promise<QueryAggregatedResult>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type HealthDataType =\n | 'steps'\n | 'distance'\n | 'calories'\n | 'heartRate'\n | 'weight'\n | 'sleep'\n | 'respiratoryRate'\n | 'oxygenSaturation'\n | 'restingHeartRate'\n | 'heartRateVariability'\n | 'bloodPressure'\n | 'bloodGlucose'\n | 'bodyTemperature'\n | 'height'\n | 'flightsClimbed'\n | 'exerciseTime'\n | 'distanceCycling'\n | 'bodyFat'\n | 'basalBodyTemperature'\n | 'basalCalories'\n | 'totalCalories'\n | 'mindfulness';\n\nexport type HealthUnit =\n | 'count'\n | 'meter'\n | 'kilocalorie'\n | 'bpm'\n | 'kilogram'\n | 'minute'\n | 'percent'\n | 'millisecond'\n | 'mmHg'\n | 'mg/dL'\n | 'celsius'\n | 'fahrenheit'\n | 'centimeter';\n\nexport interface AuthorizationOptions {\n /** Data types that should be readable after authorization. */\n read?: HealthDataType[];\n /** Data types that should be writable after authorization. */\n write?: HealthDataType[];\n}\n\nexport interface AuthorizationStatus {\n readAuthorized: HealthDataType[];\n readDenied: HealthDataType[];\n writeAuthorized: HealthDataType[];\n writeDenied: HealthDataType[];\n}\n\nexport interface AvailabilityResult {\n available: boolean;\n /** Platform specific details (for debugging/diagnostics). */\n platform?: 'ios' | 'android' | 'web';\n reason?: string;\n}\n\nexport interface QueryOptions {\n /** The type of data to retrieve from the health store. */\n dataType: HealthDataType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Maximum number of samples to return (defaults to 100). */\n limit?: number;\n /** Return results sorted ascending by start date (defaults to false). */\n ascending?: boolean;\n}\n\nexport type SleepState = 'inBed' | 'asleep' | 'awake' | 'rem' | 'deep' | 'light';\n\nexport interface HealthSample {\n dataType: HealthDataType;\n value: number;\n unit: HealthUnit;\n startDate: string;\n endDate: string;\n sourceName?: string;\n sourceId?: string;\n /** Platform-specific unique identifier (HealthKit UUID on iOS, Health Connect metadata ID on Android). */\n platformId?: string;\n /** For sleep data, indicates the sleep state (e.g., 'asleep', 'awake', 'rem', 'deep', 'light'). */\n sleepState?: SleepState;\n /** For blood pressure data, the systolic value in mmHg. */\n systolic?: number;\n /** For blood pressure data, the diastolic value in mmHg. */\n diastolic?: number;\n}\n\nexport interface ReadSamplesResult {\n samples: HealthSample[];\n}\n\nexport type WorkoutType =\n // Common types (supported on both platforms)\n | 'americanFootball'\n | 'australianFootball'\n | 'badminton'\n | 'baseball'\n | 'basketball'\n | 'bowling'\n | 'boxing'\n | 'climbing'\n | 'cricket'\n | 'crossTraining'\n | 'curling'\n | 'cycling'\n | 'dance'\n | 'elliptical'\n | 'fencing'\n | 'functionalStrengthTraining'\n | 'golf'\n | 'gymnastics'\n | 'handball'\n | 'hiking'\n | 'hockey'\n | 'jumpRope'\n | 'kickboxing'\n | 'lacrosse'\n | 'martialArts'\n | 'pilates'\n | 'racquetball'\n | 'rowing'\n | 'rugby'\n | 'running'\n | 'sailing'\n | 'skatingSports'\n | 'skiing'\n | 'snowboarding'\n | 'soccer'\n | 'softball'\n | 'squash'\n | 'stairClimbing'\n | 'strengthTraining'\n | 'surfing'\n | 'swimming'\n | 'swimmingPool'\n | 'swimmingOpenWater'\n | 'tableTennis'\n | 'tennis'\n | 'trackAndField'\n | 'traditionalStrengthTraining'\n | 'volleyball'\n | 'walking'\n | 'waterFitness'\n | 'waterPolo'\n | 'waterSports'\n | 'weightlifting'\n | 'wheelchair'\n | 'yoga'\n // iOS specific types\n | 'archery'\n | 'barre'\n | 'cooldown'\n | 'coreTraining'\n | 'crossCountrySkiing'\n | 'discSports'\n | 'downhillSkiing'\n | 'equestrianSports'\n | 'fishing'\n | 'fitnessGaming'\n | 'flexibility'\n | 'handCycling'\n | 'highIntensityIntervalTraining'\n | 'hunting'\n | 'mindAndBody'\n | 'mixedCardio'\n | 'paddleSports'\n | 'pickleball'\n | 'play'\n | 'preparationAndRecovery'\n | 'snowSports'\n | 'stairs'\n | 'stepTraining'\n | 'surfingSports'\n | 'taiChi'\n | 'transition'\n | 'underwaterDiving'\n | 'wheelchairRunPace'\n | 'wheelchairWalkPace'\n | 'wrestling'\n | 'cardioDance'\n | 'socialDance'\n // Android specific types\n | 'backExtension'\n | 'barbellShoulderPress'\n | 'benchPress'\n | 'benchSitUp'\n | 'bikingStationary'\n | 'bootCamp'\n | 'burpee'\n | 'calisthenics'\n | 'crunch'\n | 'dancing'\n | 'deadlift'\n | 'dumbbellCurlLeftArm'\n | 'dumbbellCurlRightArm'\n | 'dumbbellFrontRaise'\n | 'dumbbellLateralRaise'\n | 'dumbbellTricepsExtensionLeftArm'\n | 'dumbbellTricepsExtensionRightArm'\n | 'dumbbellTricepsExtensionTwoArm'\n | 'exerciseClass'\n | 'forwardTwist'\n | 'frisbeedisc'\n | 'guidedBreathing'\n | 'iceHockey'\n | 'iceSkating'\n | 'jumpingJack'\n | 'latPullDown'\n | 'lunge'\n | 'meditation'\n | 'paddling'\n | 'paraGliding'\n | 'plank'\n | 'rockClimbing'\n | 'rollerHockey'\n | 'rowingMachine'\n | 'runningTreadmill'\n | 'scubaDiving'\n | 'skating'\n | 'snowshoeing'\n | 'stairClimbingMachine'\n | 'stretching'\n | 'upperTwist'\n | 'other';\n\nexport interface QueryWorkoutsOptions {\n /** Optional workout type filter. If omitted, all workout types are returned. */\n workoutType?: WorkoutType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Maximum number of workouts to return (defaults to 100). */\n limit?: number;\n /** Return results sorted ascending by start date (defaults to false). */\n ascending?: boolean;\n /**\n * Anchor for pagination. Use the anchor returned from a previous query to continue from that point.\n * On iOS, this is the ISO 8601 cursor returned by the previous query. On Android, this uses\n * Health Connect's pageToken.\n * Omit this parameter to start from the beginning.\n */\n anchor?: string;\n}\n\nexport interface Workout {\n /** The type of workout. */\n workoutType: WorkoutType;\n /** Duration of the workout in seconds. */\n duration: number;\n /** Total energy burned in kilocalories (if available). */\n totalEnergyBurned?: number;\n /** Total distance in meters (if available). */\n totalDistance?: number;\n /** ISO 8601 start date of the workout. */\n startDate: string;\n /** ISO 8601 end date of the workout. */\n endDate: string;\n /** Source name that recorded the workout. */\n sourceName?: string;\n /** Source bundle identifier. */\n sourceId?: string;\n /** Platform-specific unique identifier (HealthKit UUID on iOS, Health Connect metadata ID on Android). */\n platformId?: string;\n /** Additional metadata (if available). */\n metadata?: Record<string, string>;\n}\n\nexport interface QueryWorkoutsResult {\n workouts: Workout[];\n /**\n * Anchor for the next page of results. Pass this value as the anchor parameter in the next query\n * to continue pagination. If undefined or null, there are no more results.\n */\n anchor?: string;\n}\n\nexport interface WriteSampleOptions {\n dataType: HealthDataType;\n value: number;\n /**\n * Optional unit override. If omitted, the default unit for the data type is used\n * (count for `steps`, meter for `distance`, kilocalorie for `calories`, bpm for `heartRate`, kilogram for `weight`).\n */\n unit?: HealthUnit;\n /** ISO 8601 start date for the sample. Defaults to now. */\n startDate?: string;\n /** ISO 8601 end date for the sample. Defaults to startDate. */\n endDate?: string;\n /** Metadata key-value pairs forwarded to the native APIs where supported. */\n metadata?: Record<string, string>;\n /** For blood pressure data, the systolic value in mmHg. Required when dataType is 'bloodPressure'. */\n systolic?: number;\n /** For blood pressure data, the diastolic value in mmHg. Required when dataType is 'bloodPressure'. */\n diastolic?: number;\n}\n\nexport type BucketType = 'hour' | 'day' | 'week' | 'month';\n\nexport type AggregationType = 'sum' | 'average' | 'min' | 'max';\n\nexport interface QueryAggregatedOptions {\n /** The type of data to aggregate from the health store. */\n dataType: HealthDataType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Time bucket for aggregation (defaults to 'day'). */\n bucket?: BucketType;\n /** Aggregation operation to perform (defaults to 'sum'). */\n aggregation?: AggregationType;\n}\n\nexport interface AggregatedSample {\n /** ISO 8601 start date of the bucket. */\n startDate: string;\n /** ISO 8601 end date of the bucket. */\n endDate: string;\n /** Aggregated value for the bucket. */\n value: number;\n /** Unit of the aggregated value. */\n unit: HealthUnit;\n}\n\nexport interface QueryAggregatedResult {\n samples: AggregatedSample[];\n}\n\nexport interface HealthPlugin {\n /** Returns whether the current platform supports the native health SDK. */\n isAvailable(): Promise<AvailabilityResult>;\n /** Requests read/write access to the provided data types. */\n requestAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;\n /** Checks authorization status for the provided data types without prompting the user. */\n checkAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;\n /** Reads samples for the given data type within the specified time frame. */\n readSamples(options: QueryOptions): Promise<ReadSamplesResult>;\n /** Writes a single sample to the native health store. */\n saveSample(options: WriteSampleOptions): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ version: string }>} a Promise with version for this device\n * @throws An error if something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n\n /**\n * Opens the Health Connect settings screen (Android only).\n * On iOS, this method does nothing.\n *\n * Use this to direct users to manage their Health Connect permissions\n * or to install Health Connect if not available.\n *\n * @throws An error if Health Connect settings cannot be opened\n */\n openHealthConnectSettings(): Promise<void>;\n\n /**\n * Shows the app's privacy policy for Health Connect (Android only).\n * On iOS, this method does nothing.\n *\n * This displays the same privacy policy screen that Health Connect shows\n * when the user taps \"Privacy policy\" in the permissions dialog.\n *\n * The privacy policy URL can be configured by adding a string resource\n * named \"health_connect_privacy_policy_url\" in your app's strings.xml,\n * or by placing an HTML file at www/privacypolicy.html in your assets.\n *\n * @throws An error if the privacy policy cannot be displayed\n */\n showPrivacyPolicy(): Promise<void>;\n\n /**\n * Queries workout sessions from the native health store.\n * Supported on iOS (HealthKit) and Android (Health Connect).\n *\n * @param options Query options including optional workout type filter, date range, limit, and sort order\n * @returns A promise that resolves with the workout sessions\n * @throws An error if something went wrong\n */\n queryWorkouts(options: QueryWorkoutsOptions): Promise<QueryWorkoutsResult>;\n\n /**\n * Queries aggregated health data from the native health store.\n * Aggregates data into time buckets (hour, day, week, month) with operations like sum, average, min, or max.\n * This is more efficient than fetching individual samples for large date ranges.\n *\n * Supported on iOS (HealthKit) and Android (Health Connect).\n *\n * @param options Query options including data type, date range, bucket size, and aggregation type\n * @returns A promise that resolves with the aggregated samples\n * @throws An error if something went wrong\n */\n queryAggregated(options: QueryAggregatedOptions): Promise<QueryAggregatedResult>;\n}\n"]}
|
|
@@ -898,9 +898,7 @@ final class Health {
|
|
|
898
898
|
payload["sleepState"] = sleepState
|
|
899
899
|
}
|
|
900
900
|
|
|
901
|
-
|
|
902
|
-
payload["sourceName"] = source.name
|
|
903
|
-
payload["sourceId"] = source.bundleIdentifier
|
|
901
|
+
self.addSampleMetadata(sample, to: &payload)
|
|
904
902
|
|
|
905
903
|
return payload
|
|
906
904
|
}
|
|
@@ -910,7 +908,7 @@ final class Health {
|
|
|
910
908
|
healthStore.execute(query)
|
|
911
909
|
return
|
|
912
910
|
}
|
|
913
|
-
|
|
911
|
+
|
|
914
912
|
// Handle mindfulness as a category sample
|
|
915
913
|
if dataType == .mindfulness {
|
|
916
914
|
let query = HKSampleQuery(sampleType: sampleType, predicate: predicate, limit: queryLimit, sortDescriptors: [sortDescriptor]) { [weak self] _, samples, error in
|
|
@@ -937,9 +935,7 @@ final class Health {
|
|
|
937
935
|
"endDate": self.isoFormatter.string(from: sample.endDate)
|
|
938
936
|
]
|
|
939
937
|
|
|
940
|
-
|
|
941
|
-
payload["sourceName"] = source.name
|
|
942
|
-
payload["sourceId"] = source.bundleIdentifier
|
|
938
|
+
self.addSampleMetadata(sample, to: &payload)
|
|
943
939
|
|
|
944
940
|
return payload
|
|
945
941
|
}
|
|
@@ -949,7 +945,7 @@ final class Health {
|
|
|
949
945
|
healthStore.execute(query)
|
|
950
946
|
return
|
|
951
947
|
}
|
|
952
|
-
|
|
948
|
+
|
|
953
949
|
// Handle blood pressure as a correlation sample
|
|
954
950
|
if dataType == .bloodPressure {
|
|
955
951
|
let query = HKSampleQuery(sampleType: sampleType, predicate: predicate, limit: queryLimit, sortDescriptors: [sortDescriptor]) { [weak self] _, samples, error in
|
|
@@ -986,9 +982,7 @@ final class Health {
|
|
|
986
982
|
"diastolic": diastolicValue
|
|
987
983
|
]
|
|
988
984
|
|
|
989
|
-
|
|
990
|
-
payload["sourceName"] = source.name
|
|
991
|
-
payload["sourceId"] = source.bundleIdentifier
|
|
985
|
+
self.addSampleMetadata(correlation, to: &payload)
|
|
992
986
|
|
|
993
987
|
return payload
|
|
994
988
|
}
|
|
@@ -1023,9 +1017,7 @@ final class Health {
|
|
|
1023
1017
|
"endDate": self.isoFormatter.string(from: sample.endDate)
|
|
1024
1018
|
]
|
|
1025
1019
|
|
|
1026
|
-
|
|
1027
|
-
payload["sourceName"] = source.name
|
|
1028
|
-
payload["sourceId"] = source.bundleIdentifier
|
|
1020
|
+
self.addSampleMetadata(sample, to: &payload)
|
|
1029
1021
|
|
|
1030
1022
|
return payload
|
|
1031
1023
|
}
|
|
@@ -1036,6 +1028,13 @@ final class Health {
|
|
|
1036
1028
|
healthStore.execute(query)
|
|
1037
1029
|
}
|
|
1038
1030
|
|
|
1031
|
+
private func addSampleMetadata(_ sample: HKSample, to payload: inout [String: Any]) {
|
|
1032
|
+
let source = sample.sourceRevision.source
|
|
1033
|
+
payload["sourceName"] = source.name
|
|
1034
|
+
payload["sourceId"] = source.bundleIdentifier
|
|
1035
|
+
payload["platformId"] = sample.uuid.uuidString
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1039
1038
|
private func sleepStateFromValue(_ value: Int) -> String? {
|
|
1040
1039
|
switch value {
|
|
1041
1040
|
case HKCategoryValueSleepAnalysis.inBed.rawValue:
|
|
@@ -1584,10 +1583,8 @@ final class Health {
|
|
|
1584
1583
|
payload["totalDistance"] = distanceInMeters
|
|
1585
1584
|
}
|
|
1586
1585
|
|
|
1587
|
-
// Add source information
|
|
1588
|
-
|
|
1589
|
-
payload["sourceName"] = source.name
|
|
1590
|
-
payload["sourceId"] = source.bundleIdentifier
|
|
1586
|
+
// Add source information and platform ID
|
|
1587
|
+
addSampleMetadata(workout, to: &payload)
|
|
1591
1588
|
|
|
1592
1589
|
// Add metadata if available
|
|
1593
1590
|
if let metadata = workout.metadata, !metadata.isEmpty {
|
|
@@ -3,7 +3,7 @@ import Capacitor
|
|
|
3
3
|
|
|
4
4
|
@objc(HealthPlugin)
|
|
5
5
|
public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
-
private let pluginVersion: String = "8.
|
|
6
|
+
private let pluginVersion: String = "8.4.0"
|
|
7
7
|
public let identifier = "HealthPlugin"
|
|
8
8
|
public let jsName = "Health"
|
|
9
9
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED