@kingstinct/react-native-healthkit 12.2.0 → 13.0.1
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/ReactNativeHealthkit.podspec +2 -0
- package/ios/CategoryTypeModule.swift +6 -4
- package/ios/CoreModule.swift +1 -1
- package/ios/CorrelationTypeModule.swift +16 -7
- package/ios/ExceptionCatcher.h +17 -0
- package/ios/Helpers.swift +62 -33
- package/ios/PredicateHelpers.swift +1 -1
- package/ios/QuantityTypeModule.swift +252 -128
- package/ios/StateOfMindModule.swift +4 -2
- package/ios/WorkoutsModule.swift +1 -1
- package/lib/commonjs/healthkit.ios.js +6 -2
- package/lib/commonjs/healthkit.js +13 -7
- package/lib/module/healthkit.ios.js +4 -0
- package/lib/module/healthkit.js +11 -5
- package/lib/typescript/healthkit.d.ts +6 -4
- package/lib/typescript/healthkit.ios.d.ts +12 -8
- package/lib/typescript/specs/CategoryTypeModule.nitro.d.ts +2 -2
- package/lib/typescript/specs/CorrelationTypeModule.nitro.d.ts +1 -1
- package/lib/typescript/specs/QuantityTypeModule.nitro.d.ts +4 -2
- package/lib/typescript/specs/StateOfMindModule.nitro.d.ts +1 -1
- package/lib/typescript/types/QuantitySample.d.ts +1 -1
- package/lib/typescript/types/QuantityType.d.ts +6 -1
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.cpp +57 -16
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.hpp +406 -117
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridCategoryTypeModuleSpecSwift.hpp +8 -8
- package/nitrogen/generated/ios/c++/HybridCorrelationTypeModuleSpecSwift.hpp +28 -28
- package/nitrogen/generated/ios/c++/HybridQuantityTypeModuleSpecSwift.hpp +25 -6
- package/nitrogen/generated/ios/c++/HybridStateOfMindModuleSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridWorkoutsModuleSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/AuthDataTypes.swift +1 -0
- package/nitrogen/generated/ios/swift/CategorySample.swift +1 -0
- package/nitrogen/generated/ios/swift/CategorySampleForSaving.swift +1 -0
- package/nitrogen/generated/ios/swift/CategorySamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/CorrelationSample.swift +1 -0
- package/nitrogen/generated/ios/swift/DateFilter.swift +1 -0
- package/nitrogen/generated/ios/swift/DeletedSample.swift +1 -0
- package/nitrogen/generated/ios/swift/Device.swift +1 -0
- package/nitrogen/generated/ios/swift/ECGQueryOptionsWithAnchor.swift +1 -0
- package/nitrogen/generated/ios/swift/ECGQueryOptionsWithSortOrder.swift +1 -0
- package/nitrogen/generated/ios/swift/ElectrocardiogramSample.swift +1 -0
- package/nitrogen/generated/ios/swift/ElectrocardiogramSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/ElectrocardiogramVoltage.swift +1 -0
- package/nitrogen/generated/ios/swift/FilterForSamples.swift +1 -0
- package/nitrogen/generated/ios/swift/FilterForSamplesBase.swift +1 -0
- package/nitrogen/generated/ios/swift/FilterForWorkouts.swift +54 -53
- package/nitrogen/generated/ios/swift/FilterForWorkoutsBase.swift +54 -53
- package/nitrogen/generated/ios/swift/Func_void_AuthorizationRequestStatus.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_BiologicalSex.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_BloodType.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_CategorySamplesWithAnchorResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_ElectrocardiogramSamplesWithAnchorResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_FitzpatrickSkinType.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_HeartbeatSeriesSamplesWithAnchorResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_MedicationDoseEventsWithAnchorResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_OnChangeCallbackArgs.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_QuantitySamplesWithAnchorResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_QueryCorrelationSamplesWithAnchorResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_QueryStatisticsResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_QueryWorkoutSamplesWithAnchorResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_StateOfMindSamplesWithAnchorResponse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_WheelchairUse.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_CategorySample_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_CorrelationSample_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_QuantitySample_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_QueryStatisticsResponse_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_StateOfMindSample_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_WorkoutPlan_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__chrono__system_clock__time_point_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_HybridWorkoutProxySpec_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__QueryStatisticsResponse_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__bool_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_CategorySample_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_CorrelationSample_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_ElectrocardiogramSample_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_HeartbeatSeriesSample_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_IdentifierWithUnit_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_MedicationDoseEvent_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_QuantitySample_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_QueryStatisticsResponseFromSingleSource_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_QueryStatisticsResponse_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_StateOfMindSample_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_UserAnnotatedMedication_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_WorkoutRoute_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__shared_ptr_HybridSourceProxySpec__.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__shared_ptr_HybridWorkoutProxySpec__.swift +1 -1
- package/nitrogen/generated/ios/swift/Heartbeat.swift +1 -0
- package/nitrogen/generated/ios/swift/HeartbeatSeriesSample.swift +1 -0
- package/nitrogen/generated/ios/swift/HeartbeatSeriesSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec.swift +1 -2
- package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec_cxx.swift +21 -9
- package/nitrogen/generated/ios/swift/HybridCharacteristicTypeModuleSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridCharacteristicTypeModuleSpec_cxx.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridCoreModuleSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridCoreModuleSpec_cxx.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridCorrelationTypeModuleSpec.swift +1 -2
- package/nitrogen/generated/ios/swift/HybridCorrelationTypeModuleSpec_cxx.swift +21 -9
- package/nitrogen/generated/ios/swift/HybridElectrocardiogramModuleSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridElectrocardiogramModuleSpec_cxx.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridHeartbeatSeriesModuleSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridHeartbeatSeriesModuleSpec_cxx.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridMedicationModuleSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridMedicationModuleSpec_cxx.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec.swift +3 -2
- package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec_cxx.swift +71 -9
- package/nitrogen/generated/ios/swift/HybridStateOfMindModuleSpec.swift +1 -2
- package/nitrogen/generated/ios/swift/HybridStateOfMindModuleSpec_cxx.swift +13 -8
- package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec_cxx.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridWorkoutsModuleSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridWorkoutsModuleSpec_cxx.swift +0 -1
- package/nitrogen/generated/ios/swift/IdentifierWithUnit.swift +1 -0
- package/nitrogen/generated/ios/swift/IntervalComponents.swift +1 -0
- package/nitrogen/generated/ios/swift/LocationForSaving.swift +1 -0
- package/nitrogen/generated/ios/swift/MedicationConcept.swift +1 -0
- package/nitrogen/generated/ios/swift/MedicationDoseEvent.swift +1 -0
- package/nitrogen/generated/ios/swift/MedicationDoseEventsWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/OnChangeCallbackArgs.swift +1 -0
- package/nitrogen/generated/ios/swift/PredicateWithMetadataKey.swift +1 -0
- package/nitrogen/generated/ios/swift/Quantity.swift +1 -0
- package/nitrogen/generated/ios/swift/QuantityDateInterval.swift +1 -0
- package/nitrogen/generated/ios/swift/QuantitySample.swift +1 -0
- package/nitrogen/generated/ios/swift/QuantitySampleForSaving.swift +25 -5
- package/nitrogen/generated/ios/swift/QuantitySamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/QueryCorrelationSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/QueryOptionsWithAnchor.swift +1 -0
- package/nitrogen/generated/ios/swift/QueryOptionsWithAnchorAndUnit.swift +1 -0
- package/nitrogen/generated/ios/swift/QueryOptionsWithSortOrder.swift +1 -0
- package/nitrogen/generated/ios/swift/QueryOptionsWithSortOrderAndUnit.swift +1 -0
- package/nitrogen/generated/ios/swift/QueryStatisticsResponse.swift +35 -1
- package/nitrogen/generated/ios/swift/QueryStatisticsResponseFromSingleSource.swift +267 -0
- package/nitrogen/generated/ios/swift/QueryWorkoutSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/RelatedCoding.swift +1 -0
- package/nitrogen/generated/ios/swift/SampleType.swift +1 -0
- package/nitrogen/generated/ios/swift/Source.swift +1 -0
- package/nitrogen/generated/ios/swift/SourceRevision.swift +1 -0
- package/nitrogen/generated/ios/swift/StateOfMindSample.swift +1 -0
- package/nitrogen/generated/ios/swift/StateOfMindSamplesWithAnchorResponse.swift +1 -0
- package/nitrogen/generated/ios/swift/StatisticsOptions.swift +0 -4
- package/nitrogen/generated/ios/swift/StatisticsQueryOptions.swift +1 -0
- package/nitrogen/generated/ios/swift/UserAnnotatedMedication.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutActivity.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutConfiguration.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutDurationPredicate.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutEvent.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutPlan.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutQueryOptions.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutQueryOptionsWithAnchor.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutRoute.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutRouteLocation.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutSample.swift +1 -0
- package/nitrogen/generated/ios/swift/WorkoutTotals.swift +1 -0
- package/nitrogen/generated/shared/c++/FilterForWorkouts.hpp +10 -10
- package/nitrogen/generated/shared/c++/FilterForWorkoutsBase.hpp +11 -11
- package/nitrogen/generated/shared/c++/HybridCategoryTypeModuleSpec.hpp +5 -4
- package/nitrogen/generated/shared/c++/HybridCorrelationTypeModuleSpec.hpp +5 -4
- package/nitrogen/generated/shared/c++/HybridQuantityTypeModuleSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridQuantityTypeModuleSpec.hpp +8 -3
- package/nitrogen/generated/shared/c++/HybridStateOfMindModuleSpec.hpp +2 -2
- package/nitrogen/generated/shared/c++/QuantitySampleForSaving.hpp +6 -6
- package/nitrogen/generated/shared/c++/QueryStatisticsResponse.hpp +11 -2
- package/nitrogen/generated/shared/c++/QueryStatisticsResponseFromSingleSource.hpp +121 -0
- package/nitrogen/generated/shared/c++/StatisticsOptions.hpp +0 -4
- package/package.json +4 -4
- package/src/healthkit.ios.ts +8 -0
- package/src/healthkit.ts +20 -5
- package/src/hooks/queryStatisticsForQuantity.test.ts +4 -1
- package/src/specs/CategoryTypeModule.nitro.ts +4 -4
- package/src/specs/CorrelationTypeModule.nitro.ts +2 -2
- package/src/specs/MedicationModule.nitro.ts +2 -7
- package/src/specs/QuantityTypeModule.nitro.ts +17 -2
- package/src/specs/StateOfMindModule.nitro.ts +1 -1
- package/src/types/QuantitySample.ts +1 -1
- package/src/types/QuantityType.ts +8 -1
- package/src/types/Subscriptions.ts +1 -1
|
@@ -22,6 +22,8 @@ Pod::Spec.new do |s|
|
|
|
22
22
|
"cpp/**/*.{hpp,cpp}",
|
|
23
23
|
]
|
|
24
24
|
|
|
25
|
+
s.public_header_files = "ios/**/*.h"
|
|
26
|
+
|
|
25
27
|
s.pod_target_xcconfig = {
|
|
26
28
|
# C++ compiler flags, mainly for folly.
|
|
27
29
|
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES"
|
|
@@ -7,8 +7,8 @@ class CategoryTypeModule: HybridCategoryTypeModuleSpec {
|
|
|
7
7
|
value: Double,
|
|
8
8
|
startDate: Date,
|
|
9
9
|
endDate: Date,
|
|
10
|
-
metadata: AnyMap
|
|
11
|
-
) -> Promise<
|
|
10
|
+
metadata: AnyMap?
|
|
11
|
+
) -> Promise<CategorySample?> {
|
|
12
12
|
return Promise.async {
|
|
13
13
|
let type = try initializeCategoryType(identifier.stringValue)
|
|
14
14
|
|
|
@@ -17,10 +17,12 @@ class CategoryTypeModule: HybridCategoryTypeModuleSpec {
|
|
|
17
17
|
value: Int(value),
|
|
18
18
|
start: startDate,
|
|
19
19
|
end: endDate,
|
|
20
|
-
metadata:
|
|
20
|
+
metadata: anyMapToDictionaryOptional(metadata)
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
let succeeded = try await saveAsync(sample: sample)
|
|
24
|
+
|
|
25
|
+
return succeeded ? serializeCategorySample(sample: sample) : nil
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
package/ios/CoreModule.swift
CHANGED
|
@@ -19,7 +19,7 @@ private var quantityTypeUnitCache = [HKQuantityType: HKUnit]()
|
|
|
19
19
|
|
|
20
20
|
func getUnitToUse(unitOverride: String?, quantityType: HKQuantityType) async throws -> HKUnit {
|
|
21
21
|
if let unitOverride = unitOverride {
|
|
22
|
-
let unit =
|
|
22
|
+
let unit = try parseUnitStringSafe(unitOverride)
|
|
23
23
|
|
|
24
24
|
if !quantityType.is(compatibleWith: unit) {
|
|
25
25
|
throw runtimeErrorWithPrefix(
|
|
@@ -121,8 +121,8 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
|
|
|
121
121
|
samples: [SampleForSaving],
|
|
122
122
|
start: Date,
|
|
123
123
|
end: Date,
|
|
124
|
-
metadata: AnyMap
|
|
125
|
-
) -> Promise<
|
|
124
|
+
metadata: AnyMap?
|
|
125
|
+
) -> Promise<CorrelationSample?> {
|
|
126
126
|
return Promise.async {
|
|
127
127
|
let correlationType = try initializeCorrelationType(typeIdentifier.stringValue)
|
|
128
128
|
|
|
@@ -137,14 +137,17 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
|
|
|
137
137
|
continue
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
let unit =
|
|
141
|
-
let quantity = HKQuantity(
|
|
140
|
+
let unit = try parseUnitStringSafe(quantitySample.unit)
|
|
141
|
+
let quantity = HKQuantity(
|
|
142
|
+
unit: unit,
|
|
143
|
+
doubleValue: quantitySample.quantity
|
|
144
|
+
)
|
|
142
145
|
let hkQuantitySample = HKQuantitySample(
|
|
143
146
|
type: quantityType,
|
|
144
147
|
quantity: quantity,
|
|
145
148
|
start: start,
|
|
146
149
|
end: end,
|
|
147
|
-
metadata:
|
|
150
|
+
metadata: anyMapToDictionaryOptional(quantitySample.metadata)
|
|
148
151
|
)
|
|
149
152
|
initializedSamples.insert(hkQuantitySample)
|
|
150
153
|
|
|
@@ -171,10 +174,16 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
|
|
|
171
174
|
start: start,
|
|
172
175
|
end: end,
|
|
173
176
|
objects: initializedSamples,
|
|
174
|
-
metadata:
|
|
177
|
+
metadata: anyMapToDictionaryOptional(metadata)
|
|
175
178
|
)
|
|
176
179
|
|
|
177
|
-
|
|
180
|
+
let succeeded = try await saveAsync(sample: correlation)
|
|
181
|
+
|
|
182
|
+
let unitMap = try await getUnitMap(correlations: [correlation])
|
|
183
|
+
|
|
184
|
+
return succeeded
|
|
185
|
+
? serializeCorrelationSample(correlation: correlation, unitMap: unitMap)
|
|
186
|
+
: nil
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
189
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <HealthKit/HealthKit.h>
|
|
3
|
+
|
|
4
|
+
NS_INLINE HKUnit * _Nullable HKUnitFromStringCatchingExceptions(NSString * _Nonnull unitString, NSError * _Nullable * _Nullable outError) {
|
|
5
|
+
if (outError) { *outError = nil; }
|
|
6
|
+
@try {
|
|
7
|
+
HKUnit *unit = [HKUnit unitFromString:unitString];
|
|
8
|
+
return unit;
|
|
9
|
+
}
|
|
10
|
+
@catch (NSException *exception) {
|
|
11
|
+
if (outError) {
|
|
12
|
+
NSDictionary *userInfo = exception.userInfo ?: @{};
|
|
13
|
+
*outError = [NSError errorWithDomain:exception.name code:0 userInfo:userInfo];
|
|
14
|
+
}
|
|
15
|
+
return nil;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/ios/Helpers.swift
CHANGED
|
@@ -9,6 +9,17 @@ import Foundation
|
|
|
9
9
|
import HealthKit
|
|
10
10
|
import NitroModules
|
|
11
11
|
|
|
12
|
+
func parseUnitStringSafe(_ unitString: String) throws -> HKUnit {
|
|
13
|
+
var err: NSError?
|
|
14
|
+
let unitOut = HKUnitFromStringCatchingExceptions(unitString, &err)
|
|
15
|
+
|
|
16
|
+
if let hkUnit = unitOut {
|
|
17
|
+
return hkUnit
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
throw runtimeErrorWithPrefix("Supplied invalid '\(unitString)' as HKUnit")
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
func getQueryLimit(_ limit: Double) -> Int {
|
|
13
24
|
if limit == .infinity || limit <= 0 || limit == .nan || limit == .signalingNaN {
|
|
14
25
|
return HKObjectQueryNoLimit
|
|
@@ -355,39 +366,6 @@ func objectTypeFrom(objectTypeIdentifier: ObjectTypeIdentifier) throws -> HKObje
|
|
|
355
366
|
"Failed initializing unrecognized objectType identifier " + typeIdentifier)
|
|
356
367
|
}
|
|
357
368
|
|
|
358
|
-
func hkStatisticsOptionsFromOptions(_ options: NSArray) -> HKStatisticsOptions {
|
|
359
|
-
var opts = HKStatisticsOptions()
|
|
360
|
-
|
|
361
|
-
for o in options {
|
|
362
|
-
guard let str = o as? String else { continue }
|
|
363
|
-
|
|
364
|
-
switch str {
|
|
365
|
-
case "cumulativeSum":
|
|
366
|
-
opts.insert(.cumulativeSum)
|
|
367
|
-
case "discreteAverage":
|
|
368
|
-
opts.insert(.discreteAverage)
|
|
369
|
-
case "discreteMax":
|
|
370
|
-
opts.insert(.discreteMax)
|
|
371
|
-
case "discreteMin":
|
|
372
|
-
opts.insert(.discreteMin)
|
|
373
|
-
case "duration":
|
|
374
|
-
if #available(iOS 13, *) {
|
|
375
|
-
opts.insert(.duration)
|
|
376
|
-
}
|
|
377
|
-
case "mostRecent":
|
|
378
|
-
if #available(iOS 13, *) {
|
|
379
|
-
opts.insert(.mostRecent)
|
|
380
|
-
}
|
|
381
|
-
case "separateBySource":
|
|
382
|
-
opts.insert(.separateBySource)
|
|
383
|
-
default:
|
|
384
|
-
continue
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return opts
|
|
389
|
-
}
|
|
390
|
-
|
|
391
369
|
func componentsFromInterval(_ interval: NSDictionary) -> DateComponents {
|
|
392
370
|
let componentKeys: [String: WritableKeyPath<DateComponents, Int?>] = [
|
|
393
371
|
"minute": \.minute,
|
|
@@ -421,6 +399,13 @@ func parseWorkoutConfiguration(_ config: WorkoutConfiguration) -> HKWorkoutConfi
|
|
|
421
399
|
return configuration
|
|
422
400
|
}
|
|
423
401
|
|
|
402
|
+
func anyMapToDictionaryOptional(_ anyMap: AnyMap?) -> [String: Any]? {
|
|
403
|
+
if let anyMap = anyMap {
|
|
404
|
+
return anyMapToDictionary(anyMap)
|
|
405
|
+
}
|
|
406
|
+
return nil
|
|
407
|
+
}
|
|
408
|
+
|
|
424
409
|
func anyMapToDictionary(_ anyMap: AnyMap) -> [String: Any] {
|
|
425
410
|
var dict = [String: Any]()
|
|
426
411
|
anyMap.getAllKeys().forEach { key in
|
|
@@ -436,3 +421,47 @@ func runtimeErrorWithPrefix(_ withMessage: String) -> Error {
|
|
|
436
421
|
func warnWithPrefix(_ withMessage: String) {
|
|
437
422
|
print("[react-native-healthkit] \(withMessage)")
|
|
438
423
|
}
|
|
424
|
+
|
|
425
|
+
func buildStatisticsOptions(statistics: [StatisticsOptions], quantityType: HKQuantityType) -> HKStatisticsOptions {
|
|
426
|
+
|
|
427
|
+
// Build statistics options
|
|
428
|
+
var opts = HKStatisticsOptions()
|
|
429
|
+
opts.insert(.separateBySource)
|
|
430
|
+
for statistic in statistics {
|
|
431
|
+
if statistic == .cumulativesum {
|
|
432
|
+
if quantityType.aggregationStyle == .cumulative {
|
|
433
|
+
opts.insert(HKStatisticsOptions.cumulativeSum)
|
|
434
|
+
} else {
|
|
435
|
+
warnWithPrefix("buildStatisticsOptions: cumulativesum statistic requested for discrete quantity type \(quantityType.identifier)")
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
} else if statistic == .discreteaverage {
|
|
439
|
+
if quantityType.aggregationStyle != .cumulative {
|
|
440
|
+
opts.insert(HKStatisticsOptions.discreteAverage)
|
|
441
|
+
} else {
|
|
442
|
+
warnWithPrefix("buildStatisticsOptions: discreteaverage statistic requested for cumulative quantity type \(quantityType.identifier)")
|
|
443
|
+
}
|
|
444
|
+
} else if statistic == .discretemax {
|
|
445
|
+
if quantityType.aggregationStyle != .cumulative {
|
|
446
|
+
opts.insert(HKStatisticsOptions.discreteMax)
|
|
447
|
+
} else {
|
|
448
|
+
warnWithPrefix("buildStatisticsOptions: discretemax statistic requested for cumulative quantity type \(quantityType.identifier)")
|
|
449
|
+
}
|
|
450
|
+
} else if statistic == .discretemin {
|
|
451
|
+
if quantityType.aggregationStyle != .cumulative {
|
|
452
|
+
opts.insert(HKStatisticsOptions.discreteMin)
|
|
453
|
+
} else {
|
|
454
|
+
warnWithPrefix("buildStatisticsOptions: discretemin statistic requested for cumulative quantity type \(quantityType.identifier)")
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if #available(iOS 13, *) {
|
|
458
|
+
if statistic == .duration {
|
|
459
|
+
opts.insert(HKStatisticsOptions.duration)
|
|
460
|
+
}
|
|
461
|
+
if statistic == .mostrecent {
|
|
462
|
+
opts.insert(HKStatisticsOptions.mostRecent)
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return opts
|
|
467
|
+
}
|
|
@@ -71,11 +71,11 @@ func getPredicateForWorkoutBase(_ filter: FilterForWorkouts?) -> FilterForWorkou
|
|
|
71
71
|
return FilterForWorkoutsBase(
|
|
72
72
|
workoutActivityType: filter.workoutActivityType,
|
|
73
73
|
duration: filter.duration,
|
|
74
|
+
sources: filter.sources,
|
|
74
75
|
uuid: filter.uuid,
|
|
75
76
|
uuids: filter.uuids,
|
|
76
77
|
metadata: filter.metadata,
|
|
77
78
|
date: filter.date,
|
|
78
|
-
sources: filter.sources
|
|
79
79
|
)
|
|
80
80
|
}
|
|
81
81
|
return nil
|