@capgo/capacitor-health 8.2.4 → 8.2.6
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/Package.swift
CHANGED
|
@@ -10,7 +10,7 @@ let package = Package(
|
|
|
10
10
|
targets: ["HealthPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.1")
|
|
14
14
|
],
|
|
15
15
|
targets: [
|
|
16
16
|
.target(
|
package/README.md
CHANGED
|
@@ -148,9 +148,17 @@ await Health.saveSample({
|
|
|
148
148
|
| `calories` | `kilocalorie` | Active energy burned |
|
|
149
149
|
| `heartRate`| `bpm` | Beats per minute |
|
|
150
150
|
| `weight` | `kilogram` | Body mass |
|
|
151
|
+
| `workouts` | N/A | Workout sessions (read-only, use with `queryWorkouts()`) |
|
|
151
152
|
|
|
152
153
|
All write operations expect the default unit shown above. On Android the `metadata` option is currently ignored by Health Connect.
|
|
153
154
|
|
|
155
|
+
**Note about workouts:** To query workout data using `queryWorkouts()`, you need to explicitly request `workouts` permission:
|
|
156
|
+
```ts
|
|
157
|
+
await Health.requestAuthorization({
|
|
158
|
+
read: ['steps', 'workouts'], // Include 'workouts' to access workout sessions
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
154
162
|
## API
|
|
155
163
|
|
|
156
164
|
<docgen-index>
|
|
@@ -266,10 +266,15 @@ final class Health {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
do {
|
|
269
|
-
|
|
269
|
+
// Separate "workouts" from regular health data types
|
|
270
|
+
let (readTypes, includeWorkouts) = try parseTypesWithWorkouts(readIdentifiers)
|
|
270
271
|
let writeTypes = try HealthDataType.parseMany(writeIdentifiers)
|
|
271
272
|
|
|
272
|
-
|
|
273
|
+
var readObjectTypes = try objectTypes(for: readTypes)
|
|
274
|
+
// Include workout type if explicitly requested
|
|
275
|
+
if includeWorkouts {
|
|
276
|
+
readObjectTypes.insert(HKObjectType.workoutType())
|
|
277
|
+
}
|
|
273
278
|
let writeSampleTypes = try sampleTypes(for: writeTypes)
|
|
274
279
|
|
|
275
280
|
healthStore.requestAuthorization(toShare: writeSampleTypes, read: readObjectTypes) { [weak self] success, error in
|
|
@@ -295,7 +300,7 @@ final class Health {
|
|
|
295
300
|
|
|
296
301
|
func checkAuthorization(readIdentifiers: [String], writeIdentifiers: [String], completion: @escaping (Result<AuthorizationStatusPayload, Error>) -> Void) {
|
|
297
302
|
do {
|
|
298
|
-
let readTypes = try
|
|
303
|
+
let (readTypes, _) = try parseTypesWithWorkouts(readIdentifiers)
|
|
299
304
|
let writeTypes = try HealthDataType.parseMany(writeIdentifiers)
|
|
300
305
|
|
|
301
306
|
evaluateAuthorizationStatus(readTypes: readTypes, writeTypes: writeTypes) { payload in
|
|
@@ -485,6 +490,24 @@ final class Health {
|
|
|
485
490
|
return type
|
|
486
491
|
}
|
|
487
492
|
|
|
493
|
+
private func parseTypesWithWorkouts(_ identifiers: [String]) throws -> ([HealthDataType], Bool) {
|
|
494
|
+
var types: [HealthDataType] = []
|
|
495
|
+
var includeWorkouts = false
|
|
496
|
+
|
|
497
|
+
for identifier in identifiers {
|
|
498
|
+
if identifier == "workouts" {
|
|
499
|
+
includeWorkouts = true
|
|
500
|
+
} else {
|
|
501
|
+
guard let type = HealthDataType(rawValue: identifier) else {
|
|
502
|
+
throw HealthManagerError.invalidDataType(identifier)
|
|
503
|
+
}
|
|
504
|
+
types.append(type)
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return (types, includeWorkouts)
|
|
509
|
+
}
|
|
510
|
+
|
|
488
511
|
private func parseDate(_ string: String?, defaultValue: Date) throws -> Date {
|
|
489
512
|
guard let value = string else {
|
|
490
513
|
return defaultValue
|
|
@@ -524,8 +547,6 @@ final class Health {
|
|
|
524
547
|
let type = try dataType.sampleType()
|
|
525
548
|
set.insert(type)
|
|
526
549
|
}
|
|
527
|
-
// Always include workout type for read access to enable workout queries
|
|
528
|
-
set.insert(HKObjectType.workoutType())
|
|
529
550
|
return set
|
|
530
551
|
}
|
|
531
552
|
|
|
@@ -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.2.
|
|
6
|
+
private let pluginVersion: String = "8.2.6"
|
|
7
7
|
public let identifier = "HealthPlugin"
|
|
8
8
|
public let jsName = "Health"
|
|
9
9
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED