@kingstinct/react-native-healthkit 10.0.0 → 11.0.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/ios/CoreModule.swift +5 -15
- package/ios/CorrelationTypeModule.swift +8 -2
- package/ios/Helpers.swift +50 -6
- package/ios/QuantityTypeModule.swift +72 -112
- package/ios/Serializers.swift +39 -66
- package/ios/WorkoutProxy.swift +38 -20
- package/ios/WorkoutsModule.swift +7 -18
- package/lib/commonjs/healthkit.js +1 -1
- package/lib/commonjs/hooks/useMostRecentWorkout.js +2 -9
- package/lib/commonjs/hooks/useWorkoutById.js +1 -4
- package/lib/commonjs/utils/getMostRecentWorkout.js +1 -3
- package/lib/commonjs/utils/getWorkoutById.js +1 -3
- package/lib/module/healthkit.js +1 -1
- package/lib/module/hooks/useMostRecentWorkout.js +3 -10
- package/lib/module/hooks/useWorkoutById.js +1 -4
- package/lib/module/utils/getMostRecentWorkout.js +1 -3
- package/lib/module/utils/getWorkoutById.js +1 -3
- package/lib/typescript/healthkit.d.ts +5 -5
- package/lib/typescript/healthkit.ios.d.ts +1 -1
- package/lib/typescript/hooks/useMostRecentWorkout.d.ts +1 -4
- package/lib/typescript/specs/WorkoutProxy.nitro.d.ts +11 -0
- package/lib/typescript/types/CorrelationType.d.ts +1 -0
- package/lib/typescript/types/QuantityType.d.ts +2 -0
- package/lib/typescript/types/QueryOptions.d.ts +4 -0
- package/lib/typescript/types/Workouts.d.ts +0 -8
- package/lib/typescript/utils/getMostRecentWorkout.d.ts +1 -2
- package/lib/typescript/utils/getWorkoutById.d.ts +1 -2
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.cpp +103 -87
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.hpp +798 -481
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/ReactNativeHealthkitAutolinking.mm +8 -8
- package/nitrogen/generated/ios/ReactNativeHealthkitAutolinking.swift +16 -16
- package/nitrogen/generated/ios/c++/HybridCategoryTypeModuleSpecSwift.hpp +9 -4
- package/nitrogen/generated/ios/c++/HybridCharacteristicTypeModuleSpecSwift.hpp +4 -2
- package/nitrogen/generated/ios/c++/HybridCoreModuleSpecSwift.hpp +10 -5
- package/nitrogen/generated/ios/c++/HybridCorrelationTypeModuleSpecSwift.hpp +6 -4
- package/nitrogen/generated/ios/c++/HybridHeartbeatSeriesModuleSpecSwift.hpp +10 -5
- package/nitrogen/generated/ios/c++/HybridQuantityTypeModuleSpecSwift.hpp +7 -2
- package/nitrogen/generated/ios/c++/HybridSourceProxySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/c++/HybridStateOfMindModuleSpecSwift.hpp +10 -5
- package/nitrogen/generated/ios/c++/HybridWorkoutProxySpecSwift.hpp +50 -22
- package/nitrogen/generated/ios/c++/HybridWorkoutsModuleSpecSwift.hpp +12 -7
- package/nitrogen/generated/ios/swift/CategorySample.swift +4 -2
- package/nitrogen/generated/ios/swift/CategorySampleForSaving.swift +2 -1
- package/nitrogen/generated/ios/swift/CorrelationObject.swift +2 -0
- package/nitrogen/generated/ios/swift/CorrelationSample.swift +13 -2
- package/nitrogen/generated/ios/swift/DeletedSample.swift +2 -1
- package/nitrogen/generated/ios/swift/Device.swift +16 -8
- package/nitrogen/generated/ios/swift/FilterForSamples.swift +2 -0
- package/nitrogen/generated/ios/swift/Func_void_AuthorizationRequestStatus.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_BiologicalSex.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_BloodType.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_CategorySamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_FitzpatrickSkinType.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_HeartbeatSeriesSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_OnChangeCallbackArgs.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_QuantitySamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_QueryStatisticsResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_QueryWorkoutSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_WheelchairUse.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_QueryStatisticsResponse_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_WorkoutPlan_.swift +3 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__chrono__system_clock__time_point_.swift +3 -1
- package/nitrogen/generated/ios/swift/{Func_void_std__shared_ptr_margelo__nitro__healthkit__HybridWorkoutProxySpec_.swift → Func_void_std__shared_ptr_HybridWorkoutProxySpec_.swift} +9 -8
- package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__QueryStatisticsResponse_.swift +55 -0
- package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__bool_.swift +2 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_CategorySample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_CorrelationSample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_HeartbeatSeriesSample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_IdentifierWithUnit_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_QuantitySample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_QueryStatisticsResponse_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_StateOfMindSample_.swift +1 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_WorkoutRoute_.swift +1 -0
- package/nitrogen/generated/ios/swift/{Func_void_std__vector_std__shared_ptr_margelo__nitro__healthkit__HybridSourceProxySpec__.swift → Func_void_std__vector_std__shared_ptr_HybridSourceProxySpec__.swift} +9 -8
- package/nitrogen/generated/ios/swift/{Func_void_std__vector_std__shared_ptr_margelo__nitro__healthkit__HybridWorkoutProxySpec__.swift → Func_void_std__vector_std__shared_ptr_HybridWorkoutProxySpec__.swift} +9 -8
- package/nitrogen/generated/ios/swift/HeartbeatSeriesSample.swift +6 -3
- package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec_cxx.swift +17 -7
- package/nitrogen/generated/ios/swift/HybridCharacteristicTypeModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCharacteristicTypeModuleSpec_cxx.swift +15 -6
- package/nitrogen/generated/ios/swift/HybridCoreModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCoreModuleSpec_cxx.swift +24 -15
- package/nitrogen/generated/ios/swift/HybridCorrelationTypeModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCorrelationTypeModuleSpec_cxx.swift +15 -6
- package/nitrogen/generated/ios/swift/HybridHeartbeatSeriesModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridHeartbeatSeriesModuleSpec_cxx.swift +17 -7
- package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec_cxx.swift +21 -9
- package/nitrogen/generated/ios/swift/HybridSourceProxySpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridSourceProxySpec_cxx.swift +17 -7
- package/nitrogen/generated/ios/swift/HybridStateOfMindModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridStateOfMindModuleSpec_cxx.swift +19 -8
- package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec.swift +8 -5
- package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec_cxx.swift +108 -41
- package/nitrogen/generated/ios/swift/HybridWorkoutsModuleSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridWorkoutsModuleSpec_cxx.swift +31 -22
- package/nitrogen/generated/ios/swift/OnChangeCallbackArgs.swift +2 -1
- package/nitrogen/generated/ios/swift/PredicateForSamples.swift +2 -0
- package/nitrogen/generated/ios/swift/PredicateForWorkouts.swift +2 -0
- package/nitrogen/generated/ios/swift/PredicateFromWorkout.swift +3 -3
- package/nitrogen/generated/ios/swift/PredicateWithMetadataKey.swift +95 -2
- package/nitrogen/generated/ios/swift/PredicateWithMetadataOperator.swift +48 -0
- package/nitrogen/generated/ios/swift/PredicateWithStartAndEnd.swift +4 -2
- package/nitrogen/generated/ios/swift/QuantitySample.swift +4 -2
- package/nitrogen/generated/ios/swift/QuantitySampleForSaving.swift +2 -1
- package/nitrogen/generated/ios/swift/QueryOptionsWithAnchor.swift +4 -2
- package/nitrogen/generated/ios/swift/QueryOptionsWithAnchorAndUnit.swift +6 -3
- package/nitrogen/generated/ios/swift/QueryOptionsWithSortOrder.swift +2 -1
- package/nitrogen/generated/ios/swift/QueryOptionsWithSortOrderAndUnit.swift +4 -2
- package/nitrogen/generated/ios/swift/QueryStatisticsResponse.swift +75 -8
- package/nitrogen/generated/ios/swift/QueryWorkoutSamplesWithAnchorResponse.swift +7 -7
- package/nitrogen/generated/ios/swift/SampleForSaving.swift +2 -0
- package/nitrogen/generated/ios/swift/SourceRevision.swift +13 -9
- package/nitrogen/generated/ios/swift/StateOfMindSample.swift +6 -3
- package/nitrogen/generated/ios/swift/StatisticsQueryOptions.swift +4 -2
- package/nitrogen/generated/ios/swift/Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr.swift +2 -0
- package/nitrogen/generated/ios/swift/Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_WorkoutActivityTypePredicate_WorkoutDurationPredicate_PredicateForWorkoutsOr_PredicateForWorkoutsAnd.swift +2 -0
- package/nitrogen/generated/ios/swift/Variant_String_Double_Bool_Date.swift +20 -0
- package/nitrogen/generated/ios/swift/WorkoutQueryOptions.swift +4 -61
- package/nitrogen/generated/ios/swift/WorkoutQueryOptionsWithAnchor.swift +6 -62
- package/nitrogen/generated/ios/swift/WorkoutRoute.swift +2 -1
- package/nitrogen/generated/ios/swift/WorkoutSample.swift +12 -123
- package/nitrogen/generated/shared/c++/AuthorizationRequestStatus.hpp +9 -11
- package/nitrogen/generated/shared/c++/AuthorizationStatus.hpp +9 -11
- package/nitrogen/generated/shared/c++/BiologicalSex.hpp +9 -11
- package/nitrogen/generated/shared/c++/BloodType.hpp +9 -11
- package/nitrogen/generated/shared/c++/CategorySample.hpp +14 -16
- package/nitrogen/generated/shared/c++/CategorySampleForSaving.hpp +11 -13
- package/nitrogen/generated/shared/c++/CategorySamplesWithAnchorResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/CategoryTypeIdentifier.hpp +131 -133
- package/nitrogen/generated/shared/c++/ComparisonPredicateOperator.hpp +26 -13
- package/nitrogen/generated/shared/c++/CorrelationSample.hpp +18 -15
- package/nitrogen/generated/shared/c++/CorrelationTypeIdentifier.hpp +7 -9
- package/nitrogen/generated/shared/c++/DeletedSample.hpp +5 -7
- package/nitrogen/generated/shared/c++/Device.hpp +5 -7
- package/nitrogen/generated/shared/c++/FilterForSamplesAnd.hpp +9 -11
- package/nitrogen/generated/shared/c++/FilterForSamplesOr.hpp +9 -11
- package/nitrogen/generated/shared/c++/FitzpatrickSkinType.hpp +9 -11
- package/nitrogen/generated/shared/c++/Heartbeat.hpp +4 -6
- package/nitrogen/generated/shared/c++/HeartbeatSeriesSample.hpp +15 -17
- package/nitrogen/generated/shared/c++/HeartbeatSeriesSamplesWithAnchorResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/HybridCategoryTypeModuleSpec.hpp +2 -2
- package/nitrogen/generated/shared/c++/HybridCharacteristicTypeModuleSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCoreModuleSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/HybridCorrelationTypeModuleSpec.hpp +2 -2
- package/nitrogen/generated/shared/c++/HybridHeartbeatSeriesModuleSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridQuantityTypeModuleSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridStateOfMindModuleSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/HybridWorkoutProxySpec.cpp +6 -4
- package/nitrogen/generated/shared/c++/HybridWorkoutProxySpec.hpp +18 -9
- package/nitrogen/generated/shared/c++/HybridWorkoutsModuleSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/IdentifierWithUnit.hpp +4 -6
- package/nitrogen/generated/shared/c++/IntervalComponents.hpp +4 -6
- package/nitrogen/generated/shared/c++/LocationForSaving.hpp +4 -6
- package/nitrogen/generated/shared/c++/ObjectTypeIdentifier.hpp +397 -399
- package/nitrogen/generated/shared/c++/OnChangeCallbackArgs.hpp +8 -10
- package/nitrogen/generated/shared/c++/PredicateForWorkoutsAnd.hpp +9 -11
- package/nitrogen/generated/shared/c++/PredicateForWorkoutsOr.hpp +9 -11
- package/nitrogen/generated/shared/c++/PredicateFromWorkout.hpp +6 -8
- package/nitrogen/generated/shared/c++/PredicateWithMetadataKey.hpp +20 -9
- package/nitrogen/generated/shared/c++/PredicateWithMetadataOperator.hpp +84 -0
- package/nitrogen/generated/shared/c++/PredicateWithStartAndEnd.hpp +5 -7
- package/nitrogen/generated/shared/c++/PredicateWithUUID.hpp +4 -6
- package/nitrogen/generated/shared/c++/PredicateWithUUIDs.hpp +5 -7
- package/nitrogen/generated/shared/c++/Quantity.hpp +4 -6
- package/nitrogen/generated/shared/c++/QuantityDateInterval.hpp +4 -6
- package/nitrogen/generated/shared/c++/QuantitySample.hpp +14 -16
- package/nitrogen/generated/shared/c++/QuantitySampleForSaving.hpp +11 -13
- package/nitrogen/generated/shared/c++/QuantitySamplesWithAnchorResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/QuantityTypeIdentifier.hpp +241 -243
- package/nitrogen/generated/shared/c++/QueryOptionsWithAnchor.hpp +9 -11
- package/nitrogen/generated/shared/c++/QueryOptionsWithAnchorAndUnit.hpp +9 -11
- package/nitrogen/generated/shared/c++/QueryOptionsWithSortOrder.hpp +8 -10
- package/nitrogen/generated/shared/c++/QueryOptionsWithSortOrderAndUnit.hpp +9 -11
- package/nitrogen/generated/shared/c++/QueryStatisticsResponse.hpp +36 -29
- package/nitrogen/generated/shared/c++/QueryWorkoutSamplesWithAnchorResponse.hpp +10 -12
- package/nitrogen/generated/shared/c++/SampleTypeIdentifier.hpp +383 -385
- package/nitrogen/generated/shared/c++/SampleTypeIdentifierWriteable.hpp +373 -375
- package/nitrogen/generated/shared/c++/Source.hpp +4 -6
- package/nitrogen/generated/shared/c++/SourceRevision.hpp +7 -9
- package/nitrogen/generated/shared/c++/StateOfMindAssociation.hpp +10 -12
- package/nitrogen/generated/shared/c++/StateOfMindKind.hpp +14 -13
- package/nitrogen/generated/shared/c++/StateOfMindLabel.hpp +10 -12
- package/nitrogen/generated/shared/c++/StateOfMindSample.hpp +24 -26
- package/nitrogen/generated/shared/c++/StateOfMindValenceClassification.hpp +10 -12
- package/nitrogen/generated/shared/c++/StatisticsOptions.hpp +17 -19
- package/nitrogen/generated/shared/c++/StatisticsQueryOptions.hpp +9 -11
- package/nitrogen/generated/shared/c++/UpdateFrequency.hpp +10 -12
- package/nitrogen/generated/shared/c++/WheelchairUse.hpp +9 -11
- package/nitrogen/generated/shared/c++/WorkoutActivity.hpp +4 -6
- package/nitrogen/generated/shared/c++/WorkoutActivityType.hpp +96 -13
- package/nitrogen/generated/shared/c++/WorkoutActivityTypePredicate.hpp +7 -9
- package/nitrogen/generated/shared/c++/WorkoutConfiguration.hpp +11 -13
- package/nitrogen/generated/shared/c++/WorkoutDurationPredicate.hpp +7 -9
- package/nitrogen/generated/shared/c++/WorkoutEvent.hpp +7 -9
- package/nitrogen/generated/shared/c++/WorkoutEventType.hpp +10 -12
- package/nitrogen/generated/shared/c++/WorkoutPlan.hpp +7 -9
- package/nitrogen/generated/shared/c++/WorkoutQueryOptions.hpp +10 -21
- package/nitrogen/generated/shared/c++/WorkoutQueryOptionsWithAnchor.hpp +11 -21
- package/nitrogen/generated/shared/c++/WorkoutRoute.hpp +9 -11
- package/nitrogen/generated/shared/c++/WorkoutRouteLocation.hpp +4 -6
- package/nitrogen/generated/shared/c++/WorkoutSample.hpp +25 -43
- package/nitrogen/generated/shared/c++/WorkoutSessionLocationType.hpp +10 -12
- package/nitrogen/generated/shared/c++/WorkoutTotals.hpp +4 -6
- package/package.json +11 -11
- package/src/healthkit.ts +5 -1
- package/src/hooks/queryStatisticsForQuantity.test.ts +32 -0
- package/src/hooks/useMostRecentWorkout.ts +3 -17
- package/src/hooks/useWorkoutById.ts +1 -4
- package/src/specs/WorkoutProxy.nitro.ts +18 -1
- package/src/types/CorrelationType.ts +1 -0
- package/src/types/QuantityType.ts +2 -0
- package/src/types/QueryOptions.ts +10 -0
- package/src/types/Workouts.ts +0 -8
- package/src/utils/getMostRecentWorkout.ts +1 -6
- package/src/utils/getWorkoutById.ts +1 -6
package/ios/CoreModule.swift
CHANGED
|
@@ -304,25 +304,17 @@ class CoreModule: HybridCoreModuleSpec {
|
|
|
304
304
|
|
|
305
305
|
let queryId = UUID().uuidString
|
|
306
306
|
|
|
307
|
-
func responder(
|
|
308
|
-
query: HKObserverQuery,
|
|
309
|
-
handler: @escaping HKObserverQueryCompletionHandler,
|
|
310
|
-
error: Error?
|
|
311
|
-
) {
|
|
312
|
-
DispatchQueue.main.async {
|
|
313
|
-
callback(OnChangeCallbackArgs(typeIdentifier: typeIdentifier, errorMessage: error?.localizedDescription))
|
|
314
|
-
handler()
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
307
|
let query = HKObserverQuery(
|
|
319
308
|
sampleType: sampleType,
|
|
320
309
|
predicate: predicate
|
|
321
310
|
) {
|
|
322
|
-
(
|
|
311
|
+
(_: HKObserverQuery, handler: @escaping HKObserverQueryCompletionHandler, error: Error?)
|
|
323
312
|
in
|
|
324
313
|
|
|
325
|
-
|
|
314
|
+
DispatchQueue.main.async {
|
|
315
|
+
callback(OnChangeCallbackArgs(typeIdentifier: typeIdentifier, errorMessage: error?.localizedDescription))
|
|
316
|
+
handler()
|
|
317
|
+
}
|
|
326
318
|
|
|
327
319
|
}
|
|
328
320
|
|
|
@@ -330,8 +322,6 @@ class CoreModule: HybridCoreModuleSpec {
|
|
|
330
322
|
|
|
331
323
|
self._runningQueries.updateValue(query, forKey: queryId)
|
|
332
324
|
|
|
333
|
-
// resolve(queryId)
|
|
334
|
-
|
|
335
325
|
return queryId
|
|
336
326
|
}
|
|
337
327
|
|
|
@@ -14,7 +14,8 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
|
|
|
14
14
|
var initializedSamples = Set<HKSample>()
|
|
15
15
|
|
|
16
16
|
for sample in samples {
|
|
17
|
-
|
|
17
|
+
switch sample {
|
|
18
|
+
case .second(let quantitySample):
|
|
18
19
|
let quantityTypeId = HKQuantityTypeIdentifier(rawValue: quantitySample.quantityType.stringValue)
|
|
19
20
|
guard let quantityType = HKSampleType.quantityType(forIdentifier: quantityTypeId) else {
|
|
20
21
|
continue
|
|
@@ -31,7 +32,7 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
|
|
|
31
32
|
)
|
|
32
33
|
initializedSamples.insert(hkQuantitySample)
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
case .first(let categorySample):
|
|
35
36
|
let categoryType = try initializeCategoryType(categorySample.categoryType.stringValue)
|
|
36
37
|
|
|
37
38
|
let hkCategorySample = HKCategorySample(
|
|
@@ -45,6 +46,10 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
if initializedSamples.isEmpty {
|
|
50
|
+
throw RuntimeError.error(withMessage: "[react-native-healthkit] No valid samples to create correlation sample")
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
let correlation = HKCorrelation(
|
|
49
54
|
type: correlationType,
|
|
50
55
|
start: start,
|
|
@@ -134,6 +139,7 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
|
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
return CorrelationSample(
|
|
142
|
+
uuid: correlation.uuid.uuidString,
|
|
137
143
|
correlationType: CorrelationTypeIdentifier(fromString: correlation.correlationType.identifier)!,
|
|
138
144
|
objects: objects,
|
|
139
145
|
metadata: serializeMetadata(correlation.metadata),
|
package/ios/Helpers.swift
CHANGED
|
@@ -39,7 +39,7 @@ func createPredicateForWorkout(filter: PredicateForWorkouts) throws -> NSPredica
|
|
|
39
39
|
case .second(let uuidsWrapper):
|
|
40
40
|
return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
|
|
41
41
|
case .third(let metadataKey):
|
|
42
|
-
return
|
|
42
|
+
return try createMetadataPredicate(metadataKey: metadataKey)
|
|
43
43
|
case .fourth(let dateFilter):
|
|
44
44
|
return createDatePredicate(dateFilter: dateFilter)
|
|
45
45
|
case .fifth(let w):
|
|
@@ -69,7 +69,7 @@ func createPredicateForWorkout(filter: Variant_PredicateWithUUID_PredicateWithUU
|
|
|
69
69
|
case .second(let uuidsWrapper):
|
|
70
70
|
return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
|
|
71
71
|
case .third(let metadataKey):
|
|
72
|
-
return
|
|
72
|
+
return try createMetadataPredicate(metadataKey: metadataKey)
|
|
73
73
|
case .fourth(let dateFilter):
|
|
74
74
|
return createDatePredicate(dateFilter: dateFilter)
|
|
75
75
|
case .fifth(let w):
|
|
@@ -136,6 +136,50 @@ func createUUIDsPredicate(uuidsWrapper: PredicateWithUUIDs) -> NSPredicate {
|
|
|
136
136
|
return HKQuery.predicateForObjects(with: Set(uuids))
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
func createMetadataPredicate(metadataKey: PredicateWithMetadataKey) throws -> NSPredicate {
|
|
140
|
+
guard let valueVariant = metadataKey.value else {
|
|
141
|
+
return HKQuery.predicateForObjects(withMetadataKey: metadataKey.withMetadataKey)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let actualValue: Any
|
|
145
|
+
|
|
146
|
+
switch valueVariant {
|
|
147
|
+
case .first(let stringValue):
|
|
148
|
+
actualValue = stringValue
|
|
149
|
+
case .second(let doubleValue):
|
|
150
|
+
actualValue = NSNumber(value: doubleValue)
|
|
151
|
+
case .third(let boolValue):
|
|
152
|
+
actualValue = NSNumber(value: boolValue ? 1 : 0)
|
|
153
|
+
case .fourth(let dateValue):
|
|
154
|
+
actualValue = dateValue
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let operatorType: NSComparisonPredicate.Operator
|
|
158
|
+
|
|
159
|
+
if let operatorTypeValue = metadataKey.operatorType {
|
|
160
|
+
switch operatorTypeValue {
|
|
161
|
+
case PredicateWithMetadataOperator.equalto:
|
|
162
|
+
operatorType = .equalTo
|
|
163
|
+
case PredicateWithMetadataOperator.notequalto:
|
|
164
|
+
operatorType = .notEqualTo
|
|
165
|
+
case PredicateWithMetadataOperator.greaterthan:
|
|
166
|
+
operatorType = .greaterThan
|
|
167
|
+
case PredicateWithMetadataOperator.lessthan:
|
|
168
|
+
operatorType = .lessThan
|
|
169
|
+
default:
|
|
170
|
+
throw RuntimeError.error(withMessage: "Unsupported operator: \(operatorTypeValue)")
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
operatorType = .equalTo
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return HKQuery.predicateForObjects(
|
|
177
|
+
withMetadataKey: metadataKey.withMetadataKey,
|
|
178
|
+
operatorType: operatorType,
|
|
179
|
+
value: actualValue
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
139
183
|
func createPredicate(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr?) throws -> NSPredicate? {
|
|
140
184
|
if let filter = filter {
|
|
141
185
|
switch filter {
|
|
@@ -144,7 +188,7 @@ func createPredicate(filter: Variant_PredicateWithUUID_PredicateWithUUIDs_Predic
|
|
|
144
188
|
case .second(let uuidsWrapper):
|
|
145
189
|
return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
|
|
146
190
|
case .third(let metadataKey):
|
|
147
|
-
return
|
|
191
|
+
return try createMetadataPredicate(metadataKey: metadataKey)
|
|
148
192
|
case .fourth(let dateFilter):
|
|
149
193
|
return createDatePredicate(dateFilter: dateFilter)
|
|
150
194
|
case .fifth(let w):
|
|
@@ -173,7 +217,7 @@ func createPredicateForSamples(filter: PredicateForSamples) throws -> NSPredicat
|
|
|
173
217
|
case .second(let uuidsWrapper):
|
|
174
218
|
return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
|
|
175
219
|
case .third(let metadataKey):
|
|
176
|
-
return
|
|
220
|
+
return try createMetadataPredicate(metadataKey: metadataKey)
|
|
177
221
|
case .fourth(let dateFilter):
|
|
178
222
|
return createDatePredicate(dateFilter: dateFilter)
|
|
179
223
|
case .fifth(let w):
|
|
@@ -191,7 +235,7 @@ func createPredicateForSamples(filter: FilterForSamples) throws -> NSPredicate {
|
|
|
191
235
|
case .second(let uuidsWrapper):
|
|
192
236
|
return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
|
|
193
237
|
case .third(let metadataKey):
|
|
194
|
-
return
|
|
238
|
+
return try createMetadataPredicate(metadataKey: metadataKey)
|
|
195
239
|
case .fourth(let dateFilter):
|
|
196
240
|
return createDatePredicate(dateFilter: dateFilter)
|
|
197
241
|
case .fifth(let w):
|
|
@@ -218,7 +262,7 @@ func createPredicateForSamples(filter: Variant_PredicateWithUUID_PredicateWithUU
|
|
|
218
262
|
case .second(let uuidsWrapper):
|
|
219
263
|
return createUUIDsPredicate(uuidsWrapper: uuidsWrapper)
|
|
220
264
|
case .third(let metadataKey):
|
|
221
|
-
return
|
|
265
|
+
return try createMetadataPredicate(metadataKey: metadataKey)
|
|
222
266
|
case .fourth(let dateFilter):
|
|
223
267
|
return createDatePredicate(dateFilter: dateFilter)
|
|
224
268
|
case .fifth(let w):
|
|
@@ -49,6 +49,66 @@ func queryQuantitySamplesInternal(
|
|
|
49
49
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
func serializeStatistics(gottenStats: HKStatistics, unit: HKUnit) -> QueryStatisticsResponse {
|
|
53
|
+
var response = QueryStatisticsResponse()
|
|
54
|
+
|
|
55
|
+
response.startDate = gottenStats.startDate
|
|
56
|
+
response.endDate = gottenStats.endDate
|
|
57
|
+
|
|
58
|
+
if let averageQuantity = gottenStats.averageQuantity() {
|
|
59
|
+
response.averageQuantity = Quantity(
|
|
60
|
+
unit: unit.unitString,
|
|
61
|
+
quantity: averageQuantity.doubleValue(for: unit)
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
if let maximumQuantity = gottenStats.maximumQuantity() {
|
|
65
|
+
response.maximumQuantity = Quantity(
|
|
66
|
+
unit: unit.unitString,
|
|
67
|
+
quantity: maximumQuantity.doubleValue(for: unit)
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
if let minimumQuantity = gottenStats.minimumQuantity() {
|
|
71
|
+
response.minimumQuantity = Quantity(
|
|
72
|
+
unit: unit.unitString,
|
|
73
|
+
quantity: minimumQuantity.doubleValue(for: unit)
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
if let sumQuantity = gottenStats.sumQuantity() {
|
|
77
|
+
response.sumQuantity = Quantity(
|
|
78
|
+
unit: unit.unitString,
|
|
79
|
+
quantity: sumQuantity.doubleValue(for: unit)
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if #available(iOS 12, *) {
|
|
84
|
+
if let mostRecent = gottenStats.mostRecentQuantity() {
|
|
85
|
+
response.mostRecentQuantity = Quantity(
|
|
86
|
+
unit: unit.unitString,
|
|
87
|
+
quantity: mostRecent.doubleValue(for: unit)
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if let mostRecentDateInterval = gottenStats.mostRecentQuantityDateInterval() {
|
|
92
|
+
response.mostRecentQuantityDateInterval = QuantityDateInterval(
|
|
93
|
+
from: mostRecentDateInterval.start,
|
|
94
|
+
to: mostRecentDateInterval.end
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if #available(iOS 13, *) {
|
|
100
|
+
if let duration = gottenStats.duration() {
|
|
101
|
+
let durationUnit = HKUnit.second()
|
|
102
|
+
response.duration = Quantity(
|
|
103
|
+
unit: durationUnit.unitString,
|
|
104
|
+
quantity: duration.doubleValue(for: durationUnit)
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return response
|
|
110
|
+
}
|
|
111
|
+
|
|
52
112
|
func saveQuantitySampleInternal(
|
|
53
113
|
typeIdentifier: HKQuantityType,
|
|
54
114
|
unitString: String,
|
|
@@ -178,71 +238,22 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
|
|
|
178
238
|
quantitySamplePredicate: predicate,
|
|
179
239
|
options: buildStatisticsOptions(statistics: statistics)
|
|
180
240
|
) { (_, stats: HKStatistics?, error: Error?) in
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
guard let gottenStats = stats else {
|
|
187
|
-
let emptyResponse = QueryStatisticsResponse()
|
|
188
|
-
continuation.resume(returning: emptyResponse)
|
|
189
|
-
return
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
var response = QueryStatisticsResponse()
|
|
193
|
-
|
|
194
|
-
if let averageQuantity = gottenStats.averageQuantity() {
|
|
195
|
-
response.averageQuantity = Quantity(
|
|
196
|
-
unit: unit.unitString,
|
|
197
|
-
quantity: averageQuantity.doubleValue(for: unit)
|
|
198
|
-
)
|
|
199
|
-
}
|
|
200
|
-
if let maximumQuantity = gottenStats.maximumQuantity() {
|
|
201
|
-
response.maximumQuantity = Quantity(
|
|
202
|
-
unit: unit.unitString,
|
|
203
|
-
quantity: maximumQuantity.doubleValue(for: unit)
|
|
204
|
-
)
|
|
205
|
-
}
|
|
206
|
-
if let minimumQuantity = gottenStats.minimumQuantity() {
|
|
207
|
-
response.minimumQuantity = Quantity(
|
|
208
|
-
unit: unit.unitString,
|
|
209
|
-
quantity: minimumQuantity.doubleValue(for: unit)
|
|
210
|
-
)
|
|
211
|
-
}
|
|
212
|
-
if let sumQuantity = gottenStats.sumQuantity() {
|
|
213
|
-
response.sumQuantity = Quantity(
|
|
214
|
-
unit: unit.unitString,
|
|
215
|
-
quantity: sumQuantity.doubleValue(for: unit)
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if #available(iOS 12, *) {
|
|
220
|
-
if let mostRecent = gottenStats.mostRecentQuantity() {
|
|
221
|
-
response.mostRecentQuantity = Quantity(
|
|
222
|
-
unit: unit.unitString,
|
|
223
|
-
quantity: mostRecent.doubleValue(for: unit)
|
|
224
|
-
)
|
|
241
|
+
DispatchQueue.main.async {
|
|
242
|
+
if let error = error {
|
|
243
|
+
continuation.resume(throwing: error)
|
|
244
|
+
return
|
|
225
245
|
}
|
|
226
246
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
)
|
|
247
|
+
guard let gottenStats = stats else {
|
|
248
|
+
let emptyResponse = QueryStatisticsResponse()
|
|
249
|
+
continuation.resume(returning: emptyResponse)
|
|
250
|
+
return
|
|
232
251
|
}
|
|
233
|
-
}
|
|
234
252
|
|
|
235
|
-
|
|
236
|
-
if let duration = gottenStats.duration() {
|
|
237
|
-
let durationUnit = HKUnit.second()
|
|
238
|
-
response.duration = Quantity(
|
|
239
|
-
unit: durationUnit.unitString,
|
|
240
|
-
quantity: duration.doubleValue(for: durationUnit)
|
|
241
|
-
)
|
|
242
|
-
}
|
|
243
|
-
}
|
|
253
|
+
var response = serializeStatistics(gottenStats: gottenStats, unit: unit)
|
|
244
254
|
|
|
245
|
-
|
|
255
|
+
continuation.resume(returning: response)
|
|
256
|
+
}
|
|
246
257
|
}
|
|
247
258
|
|
|
248
259
|
store.execute(query)
|
|
@@ -321,58 +332,7 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
|
|
|
321
332
|
}
|
|
322
333
|
|
|
323
334
|
statistics.enumerateStatistics(from: enumerateFrom, to: enumerateTo) { stats, _ in
|
|
324
|
-
var response =
|
|
325
|
-
|
|
326
|
-
if let averageQuantity = stats.averageQuantity() {
|
|
327
|
-
response.averageQuantity = Quantity(
|
|
328
|
-
unit: unit.unitString,
|
|
329
|
-
quantity: averageQuantity.doubleValue(for: unit)
|
|
330
|
-
)
|
|
331
|
-
}
|
|
332
|
-
if let maximumQuantity = stats.maximumQuantity() {
|
|
333
|
-
response.maximumQuantity = Quantity(
|
|
334
|
-
unit: unit.unitString,
|
|
335
|
-
quantity: maximumQuantity.doubleValue(for: unit)
|
|
336
|
-
)
|
|
337
|
-
}
|
|
338
|
-
if let minimumQuantity = stats.minimumQuantity() {
|
|
339
|
-
response.minimumQuantity = Quantity(
|
|
340
|
-
unit: unit.unitString,
|
|
341
|
-
quantity: minimumQuantity.doubleValue(for: unit)
|
|
342
|
-
)
|
|
343
|
-
}
|
|
344
|
-
if let sumQuantity = stats.sumQuantity() {
|
|
345
|
-
response.sumQuantity = Quantity(
|
|
346
|
-
unit: unit.unitString,
|
|
347
|
-
quantity: sumQuantity.doubleValue(for: unit)
|
|
348
|
-
)
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if #available(iOS 12, *) {
|
|
352
|
-
if let mostRecent = stats.mostRecentQuantity() {
|
|
353
|
-
response.mostRecentQuantity = Quantity(
|
|
354
|
-
unit: unit.unitString,
|
|
355
|
-
quantity: mostRecent.doubleValue(for: unit)
|
|
356
|
-
)
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if let mostRecentDateInterval = stats.mostRecentQuantityDateInterval() {
|
|
360
|
-
response.mostRecentQuantityDateInterval = QuantityDateInterval(
|
|
361
|
-
from: mostRecentDateInterval.start,
|
|
362
|
-
to: mostRecentDateInterval.end
|
|
363
|
-
)
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if #available(iOS 13, *) {
|
|
368
|
-
if let duration = stats.duration() {
|
|
369
|
-
let durationUnit = HKUnit.second()
|
|
370
|
-
response.duration = Quantity(
|
|
371
|
-
unit: durationUnit.unitString,
|
|
372
|
-
quantity: duration.doubleValue(for: durationUnit)
|
|
373
|
-
)
|
|
374
|
-
}
|
|
375
|
-
}
|
|
335
|
+
var response = serializeStatistics(gottenStats: stats, unit: unit)
|
|
376
336
|
|
|
377
337
|
responseArray.append(response)
|
|
378
338
|
}
|
package/ios/Serializers.swift
CHANGED
|
@@ -70,90 +70,61 @@ func serializeSource(_ source: HKSource) -> SourceProxy {
|
|
|
70
70
|
)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
func
|
|
74
|
-
|
|
75
|
-
return
|
|
73
|
+
func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
|
|
74
|
+
guard let quantity = quantity else {
|
|
75
|
+
return nil
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
if
|
|
79
|
-
return HKUnit.
|
|
78
|
+
if quantity.is(compatibleWith: HKUnit.percent()) {
|
|
79
|
+
return serializeQuantityTyped(unit: HKUnit.percent(), quantity: quantity)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
if
|
|
83
|
-
return HKUnit.
|
|
82
|
+
if quantity.is(compatibleWith: HKUnit.second()) {
|
|
83
|
+
return serializeQuantityTyped(unit: HKUnit.second(), quantity: quantity)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
if
|
|
87
|
-
return HKUnit.
|
|
86
|
+
if quantity.is(compatibleWith: HKUnit.kilocalorie()) {
|
|
87
|
+
return serializeQuantityTyped(unit: HKUnit.kilocalorie(), quantity: quantity)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
if
|
|
91
|
-
return HKUnit.
|
|
90
|
+
if quantity.is(compatibleWith: HKUnit.count()) {
|
|
91
|
+
return serializeQuantityTyped(unit: HKUnit.count(), quantity: quantity)
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
if
|
|
95
|
-
return
|
|
94
|
+
if quantity.is(compatibleWith: HKUnit.meter()) {
|
|
95
|
+
return serializeQuantityTyped(unit: HKUnit.meter(), quantity: quantity)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
if
|
|
99
|
-
return
|
|
98
|
+
if quantity.is(compatibleWith: HKUnit.degreeCelsius()) {
|
|
99
|
+
return serializeQuantityTyped(unit: HKUnit.degreeCelsius(), quantity: quantity)
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
if
|
|
103
|
-
|
|
104
|
-
return HKUnit.internationalUnit()
|
|
105
|
-
}
|
|
102
|
+
if quantity.is(compatibleWith: HKUnit.atmosphere()) {
|
|
103
|
+
return serializeQuantityTyped(unit: HKUnit.atmosphere(), quantity: quantity)
|
|
106
104
|
}
|
|
107
105
|
|
|
108
|
-
if
|
|
109
|
-
|
|
110
|
-
return HKUnit.hertz()
|
|
111
|
-
}
|
|
112
|
-
if quantityType.is(compatibleWith: HKUnit.decibelHearingLevel()) {
|
|
113
|
-
return HKUnit.decibelHearingLevel()
|
|
114
|
-
}
|
|
106
|
+
if quantity.is(compatibleWith: HKUnit.gram()) {
|
|
107
|
+
return serializeQuantityTyped(unit: HKUnit.gram(), quantity: quantity)
|
|
115
108
|
}
|
|
116
109
|
|
|
117
|
-
if
|
|
118
|
-
|
|
119
|
-
return HKUnit.lux()
|
|
120
|
-
}
|
|
110
|
+
if quantity.is(compatibleWith: HKUnit.liter()) {
|
|
111
|
+
return serializeQuantityTyped(unit: HKUnit.liter(), quantity: quantity)
|
|
121
112
|
}
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if quantityType.is(compatibleWith: HKUnit.appleEffortScore()) {
|
|
126
|
-
return HKUnit.appleEffortScore()
|
|
127
|
-
}
|
|
114
|
+
if quantity.is(compatibleWith: HKUnit.volt()) {
|
|
115
|
+
return serializeQuantityTyped(unit: HKUnit.volt(), quantity: quantity)
|
|
128
116
|
}
|
|
129
|
-
#endif
|
|
130
117
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
|
|
135
|
-
guard let quantity = quantity else {
|
|
136
|
-
return nil
|
|
118
|
+
if quantity.is(compatibleWith: HKUnit.hertz()) {
|
|
119
|
+
return serializeQuantityTyped(unit: HKUnit.hertz(), quantity: quantity)
|
|
137
120
|
}
|
|
138
121
|
|
|
139
|
-
if quantity.is(compatibleWith:
|
|
140
|
-
return serializeQuantityTyped(unit:
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if quantity.is(compatibleWith: HKUnit.second()) {
|
|
144
|
-
return serializeQuantityTyped(unit: HKUnit.second(), quantity: quantity)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if quantity.is(compatibleWith: HKUnit.kilocalorie()) {
|
|
148
|
-
return serializeQuantityTyped(unit: HKUnit.kilocalorie(), quantity: quantity)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if quantity.is(compatibleWith: HKUnit.count()) {
|
|
152
|
-
return serializeQuantityTyped(unit: HKUnit.count(), quantity: quantity)
|
|
122
|
+
if quantity.is(compatibleWith: SpeedUnit) {
|
|
123
|
+
return serializeQuantityTyped(unit: SpeedUnit, quantity: quantity)
|
|
153
124
|
}
|
|
154
125
|
|
|
155
|
-
if quantity.is(compatibleWith:
|
|
156
|
-
return serializeQuantityTyped(unit:
|
|
126
|
+
if quantity.is(compatibleWith: METUnit) {
|
|
127
|
+
return serializeQuantityTyped(unit: METUnit, quantity: quantity)
|
|
157
128
|
}
|
|
158
129
|
|
|
159
130
|
if #available(iOS 11, *) {
|
|
@@ -171,6 +142,16 @@ func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
|
|
|
171
142
|
}
|
|
172
143
|
}
|
|
173
144
|
|
|
145
|
+
if #available(iOS 16.0, *) {
|
|
146
|
+
if quantity.is(compatibleWith: HKUnit.watt()) {
|
|
147
|
+
return serializeQuantityTyped(unit: HKUnit.watt(), quantity: quantity)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if quantity.is(compatibleWith: HKUnit.degreeAngle()) {
|
|
151
|
+
return serializeQuantityTyped(unit: HKUnit.degreeAngle(), quantity: quantity)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
174
155
|
if #available(iOS 17.0, *) {
|
|
175
156
|
if quantity.is(compatibleWith: HKUnit.lux()) {
|
|
176
157
|
return serializeQuantityTyped(unit: HKUnit.lux(), quantity: quantity)
|
|
@@ -185,14 +166,6 @@ func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
|
|
|
185
166
|
}
|
|
186
167
|
#endif
|
|
187
168
|
|
|
188
|
-
if quantity.is(compatibleWith: SpeedUnit) {
|
|
189
|
-
return serializeQuantityTyped(unit: SpeedUnit, quantity: quantity)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if quantity.is(compatibleWith: METUnit) {
|
|
193
|
-
return serializeQuantityTyped(unit: METUnit, quantity: quantity)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
169
|
return nil
|
|
197
170
|
}
|
|
198
171
|
|
package/ios/WorkoutProxy.swift
CHANGED
|
@@ -149,17 +149,16 @@ func getSerializedWorkoutLocations(
|
|
|
149
149
|
previousLocation: i == 0 ? nil : routeCLLocations[i - 1]
|
|
150
150
|
)
|
|
151
151
|
}
|
|
152
|
-
// let routeInfos: WorkoutRoute = ["locations": routeLocations]
|
|
153
152
|
|
|
154
153
|
allRoutes.append(
|
|
155
154
|
WorkoutRoute(
|
|
156
155
|
locations: routeLocations,
|
|
157
|
-
HKMetadataKeySyncIdentifier: routeMetadata.getString(
|
|
156
|
+
HKMetadataKeySyncIdentifier: routeMetadata.isString(key: "HKMetadataKeySyncIdentifier") ? routeMetadata.getString(
|
|
158
157
|
key: "HKMetadataKeySyncIdentifier"
|
|
159
|
-
),
|
|
160
|
-
HKMetadataKeySyncVersion: routeMetadata.getDouble(
|
|
158
|
+
) : nil,
|
|
159
|
+
HKMetadataKeySyncVersion: routeMetadata.isDouble(key: "HKMetadataKeySyncVersion") ? routeMetadata.getDouble(
|
|
161
160
|
key: "HKMetadataKeySyncVersion"
|
|
162
|
-
)
|
|
161
|
+
) : nil
|
|
163
162
|
)
|
|
164
163
|
)
|
|
165
164
|
}
|
|
@@ -194,9 +193,39 @@ func saveWorkoutRouteInternal(
|
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
class WorkoutProxy: HybridWorkoutProxySpec {
|
|
196
|
+
|
|
197
|
+
// Return a Promise instead of directly returning the value; wrap async logic.
|
|
198
|
+
func getStatistic(quantityType: QuantityTypeIdentifier, unitOverride: String?) throws -> Promise<QueryStatisticsResponse?> {
|
|
199
|
+
return Promise.async {
|
|
200
|
+
if #available(iOS 16.0, *) {
|
|
201
|
+
let type = try initializeQuantityType(quantityType.stringValue)
|
|
202
|
+
if let stats = self.workout.statistics(for: type) {
|
|
203
|
+
let unit = try await getUnitToUse(unitOverride: unitOverride, quantityType: type)
|
|
204
|
+
return serializeStatistics(gottenStats: stats, unit: unit)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return nil
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
func getAllStatistics() throws -> Promise<[String: QueryStatisticsResponse]> {
|
|
212
|
+
return Promise.async {
|
|
213
|
+
var result: [String: QueryStatisticsResponse] = [:]
|
|
214
|
+
if #available(iOS 16.0, *) {
|
|
215
|
+
let statsMap = self.workout.allStatistics
|
|
216
|
+
for (quantityType, stats) in statsMap {
|
|
217
|
+
let unit = try await getUnitToUse(unitOverride: nil, quantityType: quantityType)
|
|
218
|
+
let serialized = serializeStatistics(gottenStats: stats, unit: unit)
|
|
219
|
+
result[quantityType.identifier] = serialized
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return result
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
197
226
|
func toJSON(key: String?) throws -> WorkoutSample {
|
|
198
|
-
if key
|
|
199
|
-
print("WorkoutProxy does not support toJSON with key: \(key
|
|
227
|
+
if let key = key, !key.isEmpty {
|
|
228
|
+
print("WorkoutProxy does not support toJSON with key: \(key)")
|
|
200
229
|
}
|
|
201
230
|
|
|
202
231
|
return WorkoutSample(
|
|
@@ -204,10 +233,6 @@ class WorkoutProxy: HybridWorkoutProxySpec {
|
|
|
204
233
|
device: self.device,
|
|
205
234
|
workoutActivityType: self.workoutActivityType,
|
|
206
235
|
duration: self.duration,
|
|
207
|
-
totalDistance: self.totalDistance,
|
|
208
|
-
totalEnergyBurned: self.totalEnergyBurned,
|
|
209
|
-
totalSwimmingStrokeCount: self.totalSwimmingStrokeCount,
|
|
210
|
-
totalFlightsClimbed: self.totalFlightsClimbed,
|
|
211
236
|
startDate: self.startDate,
|
|
212
237
|
endDate: self.endDate,
|
|
213
238
|
metadata: self.metadata,
|
|
@@ -286,7 +311,7 @@ class WorkoutProxy: HybridWorkoutProxySpec {
|
|
|
286
311
|
var totalEnergyBurned: Quantity? {
|
|
287
312
|
get {
|
|
288
313
|
return serializeQuantityTyped(
|
|
289
|
-
unit:
|
|
314
|
+
unit: HKUnit.kilocalorie(),
|
|
290
315
|
quantityNullable: workout.totalEnergyBurned
|
|
291
316
|
)
|
|
292
317
|
}
|
|
@@ -314,8 +339,6 @@ class WorkoutProxy: HybridWorkoutProxySpec {
|
|
|
314
339
|
return nil
|
|
315
340
|
}
|
|
316
341
|
|
|
317
|
-
var energyUnit: HKUnit
|
|
318
|
-
|
|
319
342
|
var startDate: Date {
|
|
320
343
|
get {
|
|
321
344
|
return workout.startDate
|
|
@@ -377,14 +400,9 @@ class WorkoutProxy: HybridWorkoutProxySpec {
|
|
|
377
400
|
return nil
|
|
378
401
|
}
|
|
379
402
|
|
|
380
|
-
let distanceUnit: HKUnit
|
|
381
|
-
|
|
382
403
|
private let workout: HKWorkout
|
|
383
404
|
|
|
384
|
-
init(workout: HKWorkout
|
|
385
|
-
self.energyUnit = energyUnit
|
|
386
|
-
self.distanceUnit = distanceUnit
|
|
387
|
-
|
|
405
|
+
init(workout: HKWorkout) {
|
|
388
406
|
self.workout = workout
|
|
389
407
|
}
|
|
390
408
|
|