@flomentumsolutions/capacitor-health-extended 0.0.9 → 0.0.10
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.
|
@@ -6,7 +6,6 @@ import HealthKit
|
|
|
6
6
|
* Please read the Capacitor iOS Plugin Development Guide
|
|
7
7
|
* here: https://capacitorjs.com/docs/plugins/ios
|
|
8
8
|
*/
|
|
9
|
-
@MainActor
|
|
10
9
|
@objc(HealthPlugin)
|
|
11
10
|
public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
12
11
|
public let identifier = "HealthPlugin"
|
|
@@ -333,17 +332,6 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
333
332
|
switch dataType.aggregationStyle {
|
|
334
333
|
case .cumulative:
|
|
335
334
|
return .cumulativeSum
|
|
336
|
-
case .discreteAverage:
|
|
337
|
-
return .discreteAverage
|
|
338
|
-
@available(iOS 17.0, *)
|
|
339
|
-
case .discreteTemporallyWeighted:
|
|
340
|
-
return .discreteAverage
|
|
341
|
-
@available(iOS 17.0, *)
|
|
342
|
-
case .discreteEquivalentContinuousLevel:
|
|
343
|
-
return .discreteAverage
|
|
344
|
-
@available(iOS 17.0, *)
|
|
345
|
-
case .discreteArithmetic:
|
|
346
|
-
return .discreteAverage
|
|
347
335
|
case .discrete:
|
|
348
336
|
return .discreteAverage
|
|
349
337
|
@unknown default:
|
|
@@ -512,8 +500,10 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
512
500
|
return
|
|
513
501
|
}
|
|
514
502
|
let outerGroup = DispatchGroup()
|
|
503
|
+
let resultsQueue = DispatchQueue(label: "com.flomentum.healthplugin.workoutResults")
|
|
515
504
|
var workoutResults: [[String: Any]] = []
|
|
516
505
|
var errors: [String: String] = [:]
|
|
506
|
+
|
|
517
507
|
for workout in workouts {
|
|
518
508
|
outerGroup.enter()
|
|
519
509
|
var localDict: [String: Any] = [
|
|
@@ -530,11 +520,16 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
530
520
|
let innerGroup = DispatchGroup()
|
|
531
521
|
var localHeartRates: [[String: Any]] = []
|
|
532
522
|
var localRoutes: [[String: Any]] = []
|
|
523
|
+
|
|
533
524
|
if includeHeartRate {
|
|
534
525
|
innerGroup.enter()
|
|
535
526
|
self.queryHeartRate(for: workout) { rates, error in
|
|
536
527
|
localHeartRates = rates
|
|
537
|
-
if let error = error {
|
|
528
|
+
if let error = error {
|
|
529
|
+
resultsQueue.async {
|
|
530
|
+
errors["heart-rate"] = error
|
|
531
|
+
}
|
|
532
|
+
}
|
|
538
533
|
innerGroup.leave()
|
|
539
534
|
}
|
|
540
535
|
}
|
|
@@ -542,7 +537,11 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
542
537
|
innerGroup.enter()
|
|
543
538
|
self.queryRoute(for: workout) { routes, error in
|
|
544
539
|
localRoutes = routes
|
|
545
|
-
if let error = error {
|
|
540
|
+
if let error = error {
|
|
541
|
+
resultsQueue.async {
|
|
542
|
+
errors["route"] = error
|
|
543
|
+
}
|
|
544
|
+
}
|
|
546
545
|
innerGroup.leave()
|
|
547
546
|
}
|
|
548
547
|
}
|
|
@@ -558,7 +557,9 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
558
557
|
innerGroup.notify(queue: .main) {
|
|
559
558
|
localDict["heartRate"] = localHeartRates
|
|
560
559
|
localDict["route"] = localRoutes
|
|
561
|
-
|
|
560
|
+
resultsQueue.async {
|
|
561
|
+
workoutResults.append(localDict)
|
|
562
|
+
}
|
|
562
563
|
outerGroup.leave()
|
|
563
564
|
}
|
|
564
565
|
}
|
|
@@ -611,11 +612,15 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
611
612
|
guard let self = self else { return }
|
|
612
613
|
if let routes = samples as? [HKWorkoutRoute], error == nil {
|
|
613
614
|
let routeDispatchGroup = DispatchGroup()
|
|
615
|
+
let allLocationsQueue = DispatchQueue(label: "com.flomentum.healthplugin.allLocations")
|
|
614
616
|
var allLocations: [[String: Any]] = []
|
|
617
|
+
|
|
615
618
|
for route in routes {
|
|
616
619
|
routeDispatchGroup.enter()
|
|
617
620
|
self.queryLocations(for: route) { locations in
|
|
618
|
-
|
|
621
|
+
allLocationsQueue.async {
|
|
622
|
+
allLocations.append(contentsOf: locations)
|
|
623
|
+
}
|
|
619
624
|
routeDispatchGroup.leave()
|
|
620
625
|
}
|
|
621
626
|
}
|
|
@@ -634,8 +639,6 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
634
639
|
|
|
635
640
|
// MARK: - Query Route Locations
|
|
636
641
|
private func queryLocations(for route: HKWorkoutRoute, completion: @escaping @Sendable ([[String: Any]]) -> Void) {
|
|
637
|
-
var routeLocations: [[String: Any]] = []
|
|
638
|
-
|
|
639
642
|
let locationQuery = HKWorkoutRouteQuery(route: route) { [weak self] _, locations, done, error in
|
|
640
643
|
guard let self = self else { return }
|
|
641
644
|
guard let locations = locations, error == nil else {
|
|
@@ -645,8 +648,10 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
645
648
|
return
|
|
646
649
|
}
|
|
647
650
|
|
|
648
|
-
//
|
|
651
|
+
// Process locations on the serial queue to avoid race conditions
|
|
649
652
|
self.routeSyncQueue.async {
|
|
653
|
+
var routeLocations: [[String: Any]] = []
|
|
654
|
+
|
|
650
655
|
for location in locations {
|
|
651
656
|
let locationDict: [String: Any] = [
|
|
652
657
|
"timestamp": location.timestamp,
|
package/package.json
CHANGED