@kingstinct/react-native-healthkit 6.1.1 → 7.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/README.md +7 -5
- package/app.plugin.js +23 -4
- package/ios/Constants.swift +28 -0
- package/ios/Helpers.swift +152 -0
- package/ios/ReactNativeHealthkit.m +24 -0
- package/ios/ReactNativeHealthkit.swift +534 -728
- package/ios/Serializers.swift +206 -0
- package/lib/commonjs/hooks/useHealthkitAuthorization.js +0 -6
- package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +1 -1
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js +2 -9
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js.map +1 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js +0 -6
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js +1 -6
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentCategorySample.js +1 -7
- package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js +0 -10
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentWorkout.js +0 -10
- package/lib/commonjs/hooks/useMostRecentWorkout.js.map +1 -1
- package/lib/commonjs/hooks/useSources.js +0 -5
- package/lib/commonjs/hooks/useSources.js.map +1 -1
- package/lib/commonjs/hooks/useStatisticsForQuantity.js +1 -7
- package/lib/commonjs/hooks/useStatisticsForQuantity.js.map +1 -1
- package/lib/commonjs/hooks/useSubscribeToChanges.js +0 -8
- package/lib/commonjs/hooks/useSubscribeToChanges.js.map +1 -1
- package/lib/commonjs/index.ios.js +6 -33
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +7 -11
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/jest.setup.js +3 -1
- package/lib/commonjs/jest.setup.js.map +1 -1
- package/lib/commonjs/native-types.js +166 -250
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/test-utils.js +1 -3
- package/lib/commonjs/test-utils.js.map +1 -1
- package/lib/commonjs/types.js +0 -2
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/deleteQuantitySample.js +0 -4
- package/lib/commonjs/utils/deleteQuantitySample.js.map +1 -1
- package/lib/commonjs/utils/deleteSamples.js +0 -4
- package/lib/commonjs/utils/deleteSamples.js.map +1 -1
- package/lib/commonjs/utils/deserializeCategorySample.js +2 -3
- package/lib/commonjs/utils/deserializeCategorySample.js.map +1 -1
- package/lib/commonjs/utils/deserializeCategorySample.test.js +3 -5
- package/lib/commonjs/utils/deserializeCategorySample.test.js.map +1 -1
- package/lib/commonjs/utils/deserializeCorrelation.js +2 -7
- package/lib/commonjs/utils/deserializeCorrelation.js.map +1 -1
- package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js +2 -3
- package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js.map +1 -1
- package/lib/commonjs/utils/deserializeSample.js +2 -3
- package/lib/commonjs/utils/deserializeSample.js.map +1 -1
- package/lib/commonjs/utils/deserializeWorkout.js +2 -3
- package/lib/commonjs/utils/deserializeWorkout.js.map +1 -1
- package/lib/commonjs/utils/ensureMetadata.js +0 -2
- package/lib/commonjs/utils/ensureMetadata.js.map +1 -1
- package/lib/commonjs/utils/ensureUnit.js +0 -5
- package/lib/commonjs/utils/ensureUnit.js.map +1 -1
- package/lib/commonjs/utils/getDateOfBirth.js +0 -4
- package/lib/commonjs/utils/getDateOfBirth.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentCategorySample.js +1 -5
- package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js +1 -5
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentWorkout.js +0 -4
- package/lib/commonjs/utils/getMostRecentWorkout.js.map +1 -1
- package/lib/commonjs/utils/getPreferredUnit.js +0 -4
- package/lib/commonjs/utils/getPreferredUnit.js.map +1 -1
- package/lib/commonjs/utils/getPreferredUnits.js +0 -4
- package/lib/commonjs/utils/getPreferredUnits.js.map +1 -1
- package/lib/commonjs/utils/getPreferredUnitsTyped.js +0 -11
- package/lib/commonjs/utils/getPreferredUnitsTyped.js.map +1 -1
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js +4 -6
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js.map +1 -1
- package/lib/commonjs/utils/prepareOptions.js +0 -4
- package/lib/commonjs/utils/prepareOptions.js.map +1 -1
- package/lib/commonjs/utils/queryCategorySamples.js +3 -14
- package/lib/commonjs/utils/queryCategorySamples.js.map +1 -1
- package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js +22 -0
- package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js.map +1 -0
- package/lib/commonjs/utils/queryCorrelationSamples.js +1 -7
- package/lib/commonjs/utils/queryCorrelationSamples.js.map +1 -1
- package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js +3 -13
- package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js.map +1 -1
- package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js +22 -0
- package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +1 -0
- package/lib/commonjs/utils/queryQuantitySamples.js +3 -15
- package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -1
- package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js +24 -0
- package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js.map +1 -0
- package/lib/commonjs/utils/querySources.js +0 -4
- package/lib/commonjs/utils/querySources.js.map +1 -1
- package/lib/commonjs/utils/queryStatisticsForQuantity.js +3 -7
- package/lib/commonjs/utils/queryStatisticsForQuantity.js.map +1 -1
- package/lib/commonjs/utils/queryWorkouts.js +1 -8
- package/lib/commonjs/utils/queryWorkouts.js.map +1 -1
- package/lib/commonjs/utils/requestAuthorization.js +4 -6
- package/lib/commonjs/utils/requestAuthorization.js.map +1 -1
- package/lib/commonjs/utils/saveCategorySample.js +0 -4
- package/lib/commonjs/utils/saveCategorySample.js.map +1 -1
- package/lib/commonjs/utils/saveCorrelationSample.js +3 -7
- package/lib/commonjs/utils/saveCorrelationSample.js.map +1 -1
- package/lib/commonjs/utils/saveQuantitySample.js +0 -4
- package/lib/commonjs/utils/saveQuantitySample.js.map +1 -1
- package/lib/commonjs/utils/saveWorkoutSample.js +3 -8
- package/lib/commonjs/utils/saveWorkoutSample.js.map +1 -1
- package/lib/commonjs/utils/serializeDate.js +0 -2
- package/lib/commonjs/utils/serializeDate.js.map +1 -1
- package/lib/commonjs/utils/serializeDate.test.js +0 -2
- package/lib/commonjs/utils/serializeDate.test.js.map +1 -1
- package/lib/commonjs/utils/subscribeToChanges.js +0 -7
- package/lib/commonjs/utils/subscribeToChanges.js.map +1 -1
- package/lib/module/hooks/useHealthkitAuthorization.js +0 -2
- package/lib/module/hooks/useHealthkitAuthorization.js.map +1 -1
- package/lib/module/hooks/useHealthkitAuthorization.test.js +1 -1
- package/lib/module/hooks/useHealthkitAuthorization.test.js.map +1 -1
- package/lib/module/hooks/useIsHealthDataAvailable.js +0 -3
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/module/hooks/useIsHealthDataAvailable.test.js +1 -1
- package/lib/module/hooks/useIsHealthDataAvailable.test.js.map +1 -1
- package/lib/module/hooks/useMostRecentCategorySample.js +1 -3
- package/lib/module/hooks/useMostRecentCategorySample.js.map +1 -1
- package/lib/module/hooks/useMostRecentQuantitySample.js +0 -5
- package/lib/module/hooks/useMostRecentQuantitySample.js.map +1 -1
- package/lib/module/hooks/useMostRecentWorkout.js +0 -5
- package/lib/module/hooks/useMostRecentWorkout.js.map +1 -1
- package/lib/module/hooks/useSources.js +0 -2
- package/lib/module/hooks/useSources.js.map +1 -1
- package/lib/module/hooks/useStatisticsForQuantity.js +1 -3
- package/lib/module/hooks/useStatisticsForQuantity.js.map +1 -1
- package/lib/module/hooks/useSubscribeToChanges.js +0 -5
- package/lib/module/hooks/useSubscribeToChanges.js.map +1 -1
- package/lib/module/index.ios.js +6 -0
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +8 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest.setup.js +3 -0
- package/lib/module/jest.setup.js.map +1 -1
- package/lib/module/native-types.js +134 -201
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/test-utils.js +0 -2
- package/lib/module/test-utils.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/deleteQuantitySample.js +0 -2
- package/lib/module/utils/deleteQuantitySample.js.map +1 -1
- package/lib/module/utils/deleteSamples.js +0 -2
- package/lib/module/utils/deleteSamples.js.map +1 -1
- package/lib/module/utils/deserializeCategorySample.js +2 -2
- package/lib/module/utils/deserializeCategorySample.js.map +1 -1
- package/lib/module/utils/deserializeCategorySample.test.js +3 -2
- package/lib/module/utils/deserializeCategorySample.test.js.map +1 -1
- package/lib/module/utils/deserializeCorrelation.js +2 -4
- package/lib/module/utils/deserializeCorrelation.js.map +1 -1
- package/lib/module/utils/deserializeHeartbeatSeriesSample.js +2 -2
- package/lib/module/utils/deserializeHeartbeatSeriesSample.js.map +1 -1
- package/lib/module/utils/deserializeSample.js +2 -2
- package/lib/module/utils/deserializeSample.js.map +1 -1
- package/lib/module/utils/deserializeWorkout.js +2 -2
- package/lib/module/utils/deserializeWorkout.js.map +1 -1
- package/lib/module/utils/ensureMetadata.js +0 -1
- package/lib/module/utils/ensureMetadata.js.map +1 -1
- package/lib/module/utils/ensureUnit.js +0 -3
- package/lib/module/utils/ensureUnit.js.map +1 -1
- package/lib/module/utils/getDateOfBirth.js +0 -2
- package/lib/module/utils/getDateOfBirth.js.map +1 -1
- package/lib/module/utils/getMostRecentCategorySample.js +1 -3
- package/lib/module/utils/getMostRecentCategorySample.js.map +1 -1
- package/lib/module/utils/getMostRecentQuantitySample.js +1 -3
- package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/module/utils/getMostRecentWorkout.js +0 -2
- package/lib/module/utils/getMostRecentWorkout.js.map +1 -1
- package/lib/module/utils/getPreferredUnit.js +0 -2
- package/lib/module/utils/getPreferredUnit.js.map +1 -1
- package/lib/module/utils/getPreferredUnits.js +0 -2
- package/lib/module/utils/getPreferredUnits.js.map +1 -1
- package/lib/module/utils/getPreferredUnitsTyped.js +0 -8
- package/lib/module/utils/getPreferredUnitsTyped.js.map +1 -1
- package/lib/module/utils/getRequestStatusForAuthorization.js +4 -4
- package/lib/module/utils/getRequestStatusForAuthorization.js.map +1 -1
- package/lib/module/utils/prepareOptions.js +0 -2
- package/lib/module/utils/prepareOptions.js.map +1 -1
- package/lib/module/utils/queryCategorySamples.js +3 -10
- package/lib/module/utils/queryCategorySamples.js.map +1 -1
- package/lib/module/utils/queryCategorySamplesWithAnchor.js +14 -0
- package/lib/module/utils/queryCategorySamplesWithAnchor.js.map +1 -0
- package/lib/module/utils/queryCorrelationSamples.js +1 -3
- package/lib/module/utils/queryCorrelationSamples.js.map +1 -1
- package/lib/module/utils/queryHeartbeatSeriesSamples.js +3 -9
- package/lib/module/utils/queryHeartbeatSeriesSamples.js.map +1 -1
- package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js +14 -0
- package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +1 -0
- package/lib/module/utils/queryQuantitySamples.js +3 -10
- package/lib/module/utils/queryQuantitySamples.js.map +1 -1
- package/lib/module/utils/queryQuantitySamplesWithAnchor.js +16 -0
- package/lib/module/utils/queryQuantitySamplesWithAnchor.js.map +1 -0
- package/lib/module/utils/querySources.js +0 -2
- package/lib/module/utils/querySources.js.map +1 -1
- package/lib/module/utils/queryStatisticsForQuantity.js +3 -4
- package/lib/module/utils/queryStatisticsForQuantity.js.map +1 -1
- package/lib/module/utils/queryWorkouts.js +1 -3
- package/lib/module/utils/queryWorkouts.js.map +1 -1
- package/lib/module/utils/requestAuthorization.js +4 -4
- package/lib/module/utils/requestAuthorization.js.map +1 -1
- package/lib/module/utils/saveCategorySample.js +0 -2
- package/lib/module/utils/saveCategorySample.js.map +1 -1
- package/lib/module/utils/saveCorrelationSample.js +3 -4
- package/lib/module/utils/saveCorrelationSample.js.map +1 -1
- package/lib/module/utils/saveQuantitySample.js +0 -2
- package/lib/module/utils/saveQuantitySample.js.map +1 -1
- package/lib/module/utils/saveWorkoutSample.js +3 -5
- package/lib/module/utils/saveWorkoutSample.js.map +1 -1
- package/lib/module/utils/serializeDate.js +0 -1
- package/lib/module/utils/serializeDate.js.map +1 -1
- package/lib/module/utils/serializeDate.test.js.map +1 -1
- package/lib/module/utils/subscribeToChanges.js +0 -3
- package/lib/module/utils/subscribeToChanges.js.map +1 -1
- package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +2 -3
- package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +2 -3
- package/lib/typescript/src/index.ios.d.ts +4 -1
- package/lib/typescript/src/native-types.d.ts +66 -63
- package/lib/typescript/src/types.d.ts +3 -3
- package/lib/typescript/src/utils/deleteQuantitySample.d.ts +1 -1
- package/lib/typescript/src/utils/deleteSamples.d.ts +1 -1
- package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +1 -1
- package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +1 -1
- package/lib/typescript/src/utils/getMostRecentWorkout.d.ts +1 -1
- package/lib/typescript/src/utils/getPreferredUnit.d.ts +1 -1
- package/lib/typescript/src/utils/getPreferredUnits.d.ts +1 -1
- package/lib/typescript/src/utils/queryCategorySamples.d.ts +3 -8
- package/lib/typescript/src/utils/queryCategorySamplesWithAnchor.d.ts +10 -0
- package/lib/typescript/src/utils/queryCorrelationSamples.d.ts +1 -1
- package/lib/typescript/src/utils/queryHeartbeatSeriesSamples.d.ts +2 -2
- package/lib/typescript/src/utils/queryHeartbeatSeriesSamplesWithAnchor.d.ts +10 -0
- package/lib/typescript/src/utils/queryQuantitySamples.d.ts +4 -9
- package/lib/typescript/src/utils/queryQuantitySamplesWithAnchor.d.ts +12 -0
- package/lib/typescript/src/utils/querySources.d.ts +1 -1
- package/package.json +18 -17
- package/src/hooks/useHealthkitAuthorization.test.ts +1 -1
- package/src/hooks/useIsHealthDataAvailable.test.ts +1 -1
- package/src/hooks/useMostRecentCategorySample.ts +3 -4
- package/src/hooks/useMostRecentQuantitySample.ts +2 -3
- package/src/hooks/useStatisticsForQuantity.ts +1 -1
- package/src/index.ios.tsx +6 -0
- package/src/index.tsx +10 -5
- package/src/jest.setup.ts +3 -0
- package/src/native-types.ts +28 -7
- package/src/utils/deserializeCategorySample.test.ts +1 -1
- package/src/utils/getMostRecentCategorySample.ts +1 -1
- package/src/utils/getMostRecentQuantitySample.ts +1 -1
- package/src/utils/queryCategorySamples.ts +6 -18
- package/src/utils/queryCategorySamplesWithAnchor.ts +39 -0
- package/src/utils/queryCorrelationSamples.ts +2 -2
- package/src/utils/queryHeartbeatSeriesSamples.ts +3 -8
- package/src/utils/queryHeartbeatSeriesSamplesWithAnchor.ts +33 -0
- package/src/utils/queryQuantitySamples.ts +8 -18
- package/src/utils/queryQuantitySamplesWithAnchor.ts +46 -0
- package/src/utils/queryStatisticsForQuantity.ts +1 -1
- package/src/utils/queryWorkouts.ts +1 -1
- package/src/utils/saveCorrelationSample.ts +1 -1
- package/src/utils/saveWorkoutSample.ts +1 -1
- package/android/.project +0 -34
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/android/build.gradle +0 -130
- package/android/gradle.properties +0 -4
- package/android/src/main/AndroidManifest.xml +0 -4
- package/android/src/main/java/com/kingstinctreactnativehealthkit/ReactNativeHealthkitModule.kt +0 -24
- package/android/src/main/java/com/kingstinctreactnativehealthkit/ReactNativeHealthkitPackage.kt +0 -20
package/README.md
CHANGED
|
@@ -37,11 +37,13 @@ this will give you defaults that make the app build without any further configur
|
|
|
37
37
|
```json
|
|
38
38
|
{
|
|
39
39
|
"expo": {
|
|
40
|
-
"plugins": [
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
"plugins": [
|
|
41
|
+
["@kingstinct/react-native-healthkit", {
|
|
42
|
+
"NSHealthShareUsageDescription": "Your own custom usage description",
|
|
43
|
+
"NSHealthUpdateUsageDescription": false, // if you have no plans to update data, you can skip adding it to your info.plist
|
|
44
|
+
"background": false // if you have no plans to use it in background mode, skip adding it to the entitlements
|
|
45
|
+
}]
|
|
46
|
+
]
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
```
|
package/app.plugin.js
CHANGED
|
@@ -40,16 +40,35 @@ const {
|
|
|
40
40
|
*/
|
|
41
41
|
const withEntitlementsPlugin = (config, { background }) => withEntitlementsPlist(config, (config) => {
|
|
42
42
|
config.modResults['com.apple.developer.healthkit'] = true
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
// background is enabled by default, but possible to opt-out from
|
|
45
|
+
// (haven't seen any drawbacks from having it enabled)
|
|
46
|
+
if (background !== false) {
|
|
47
|
+
config.modResults['com.apple.developer.healthkit.background-delivery'] = true
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
return config
|
|
45
51
|
})
|
|
46
52
|
|
|
47
53
|
/**
|
|
48
54
|
* @type {ConfigPlugin<InfoPlistConfig>}
|
|
49
55
|
*/
|
|
50
|
-
const withInfoPlistPlugin = (config,
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
const withInfoPlistPlugin = (config,
|
|
57
|
+
/**
|
|
58
|
+
* @type {{NSHealthShareUsageDescription: string | boolean, NSHealthUpdateUsageDescription: string | boolean}}
|
|
59
|
+
* */
|
|
60
|
+
{
|
|
61
|
+
NSHealthShareUsageDescription,
|
|
62
|
+
NSHealthUpdateUsageDescription,
|
|
63
|
+
}) => withInfoPlist(config, (config) => {
|
|
64
|
+
if (NSHealthShareUsageDescription !== false) {
|
|
65
|
+
config.modResults.NSHealthShareUsageDescription = NSHealthShareUsageDescription ?? `${config.name} wants to read your health data`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (NSHealthUpdateUsageDescription !== false) {
|
|
69
|
+
config.modResults.NSHealthUpdateUsageDescription = NSHealthUpdateUsageDescription ?? `${config.name} wants to update your health data`
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
return config
|
|
54
73
|
})
|
|
55
74
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Constants.swift
|
|
3
|
+
// kingstinct-react-native-healthkit
|
|
4
|
+
//
|
|
5
|
+
// Created by Robert Herber on 2023-05-31.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import HealthKit
|
|
10
|
+
|
|
11
|
+
let INIT_ERROR = "HEALTHKIT_INIT_ERROR"
|
|
12
|
+
let INIT_ERROR_MESSAGE = "HealthKit not initialized"
|
|
13
|
+
let TYPE_IDENTIFIER_ERROR = "HEALTHKIT_TYPE_IDENTIFIER_NOT_RECOGNIZED_ERROR"
|
|
14
|
+
let GENERIC_ERROR = "HEALTHKIT_ERROR"
|
|
15
|
+
|
|
16
|
+
let HKCharacteristicTypeIdentifier_PREFIX = "HKCharacteristicTypeIdentifier"
|
|
17
|
+
let HKQuantityTypeIdentifier_PREFIX = "HKQuantityTypeIdentifier"
|
|
18
|
+
let HKCategoryTypeIdentifier_PREFIX = "HKCategoryTypeIdentifier"
|
|
19
|
+
let HKCorrelationTypeIdentifier_PREFIX = "HKCorrelationTypeIdentifier"
|
|
20
|
+
let HKActivitySummaryTypeIdentifier = "HKActivitySummaryTypeIdentifier"
|
|
21
|
+
let HKAudiogramTypeIdentifier = "HKAudiogramTypeIdentifier"
|
|
22
|
+
let HKWorkoutTypeIdentifier = "HKWorkoutTypeIdentifier"
|
|
23
|
+
let HKWorkoutRouteTypeIdentifier = "HKWorkoutRouteTypeIdentifier"
|
|
24
|
+
let HKDataTypeIdentifierHeartbeatSeries = "HKDataTypeIdentifierHeartbeatSeries"
|
|
25
|
+
|
|
26
|
+
let SpeedUnit = HKUnit(from: "m/s") // HKUnit.meter().unitDivided(by: HKUnit.second())
|
|
27
|
+
// Support for MET data: HKAverageMETs 8.24046 kcal/hr·kg
|
|
28
|
+
let METUnit = HKUnit(from: "kcal/hr·kg")
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Helpers.swift
|
|
3
|
+
// kingstinct-react-native-healthkit
|
|
4
|
+
//
|
|
5
|
+
// Created by Robert Herber on 2023-05-31.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import HealthKit
|
|
10
|
+
|
|
11
|
+
func dateOrNilIfZero(date: Date) -> Date? {
|
|
12
|
+
return date.timeIntervalSince1970 > 0 ? date : nil
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func limitOrNilIfZero(limit: Int) -> Int {
|
|
16
|
+
return limit == 0 ? HKObjectQueryNoLimit : limit
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func createPredicate(from: Date?, to: Date?) -> NSPredicate? {
|
|
20
|
+
if from != nil || to != nil {
|
|
21
|
+
return HKQuery.predicateForSamples(withStart: from, end: to, options: [.strictEndDate, .strictStartDate])
|
|
22
|
+
} else {
|
|
23
|
+
return nil
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func getSortDescriptors(ascending: Bool) -> [NSSortDescriptor] {
|
|
28
|
+
return [NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: ascending)]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func base64StringToHKQueryAnchor(base64String: String) -> HKQueryAnchor? {
|
|
32
|
+
// Step 1: Decode the base64 string to a Data object
|
|
33
|
+
guard let data = Data(base64Encoded: base64String) else {
|
|
34
|
+
print("Error: Invalid base64 string")
|
|
35
|
+
return nil
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Step 2: Use NSKeyedUnarchiver to unarchive the data and create an HKQueryAnchor object
|
|
39
|
+
do {
|
|
40
|
+
let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data)
|
|
41
|
+
unarchiver.requiresSecureCoding = true
|
|
42
|
+
let anchor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data)
|
|
43
|
+
|
|
44
|
+
return anchor as? HKQueryAnchor
|
|
45
|
+
} catch {
|
|
46
|
+
print("Error: Unable to unarchive HKQueryAnchor object: \(error)")
|
|
47
|
+
return nil
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func sampleTypeFromString(typeIdentifier: String) -> HKSampleType? {
|
|
52
|
+
if typeIdentifier.starts(with: HKQuantityTypeIdentifier_PREFIX) {
|
|
53
|
+
let identifier = HKQuantityTypeIdentifier.init(rawValue: typeIdentifier)
|
|
54
|
+
return HKSampleType.quantityType(forIdentifier: identifier) as HKSampleType?
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if typeIdentifier.starts(with: HKCategoryTypeIdentifier_PREFIX) {
|
|
58
|
+
let identifier = HKCategoryTypeIdentifier.init(rawValue: typeIdentifier)
|
|
59
|
+
return HKSampleType.categoryType(forIdentifier: identifier) as HKSampleType?
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if typeIdentifier.starts(with: HKCorrelationTypeIdentifier_PREFIX) {
|
|
63
|
+
let identifier = HKCorrelationTypeIdentifier.init(rawValue: typeIdentifier)
|
|
64
|
+
return HKSampleType.correlationType(forIdentifier: identifier) as HKSampleType?
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if #available(iOS 13, *) {
|
|
68
|
+
if typeIdentifier == HKAudiogramTypeIdentifier {
|
|
69
|
+
return HKSampleType.audiogramSampleType()
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if typeIdentifier == HKWorkoutTypeIdentifier {
|
|
74
|
+
return HKSampleType.workoutType()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return nil
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
func objectTypesFromDictionary(typeIdentifiers: NSDictionary) -> Set<HKObjectType> {
|
|
81
|
+
var share = Set<HKObjectType>()
|
|
82
|
+
for item in typeIdentifiers {
|
|
83
|
+
if item.value as! Bool {
|
|
84
|
+
let objectType = objectTypeFromString(typeIdentifier: item.key as! String)
|
|
85
|
+
if objectType != nil {
|
|
86
|
+
share.insert(objectType!)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return share
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
func sampleTypesFromDictionary(typeIdentifiers: NSDictionary) -> Set<HKSampleType> {
|
|
94
|
+
var share = Set<HKSampleType>()
|
|
95
|
+
for item in typeIdentifiers {
|
|
96
|
+
if item.value as! Bool {
|
|
97
|
+
let sampleType = sampleTypeFromString(typeIdentifier: item.key as! String)
|
|
98
|
+
if sampleType != nil {
|
|
99
|
+
share.insert(sampleType!)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return share
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func objectTypeFromString(typeIdentifier: String) -> HKObjectType? {
|
|
107
|
+
if typeIdentifier.starts(with: HKCharacteristicTypeIdentifier_PREFIX) {
|
|
108
|
+
let identifier = HKCharacteristicTypeIdentifier.init(rawValue: typeIdentifier)
|
|
109
|
+
return HKObjectType.characteristicType(forIdentifier: identifier) as HKObjectType?
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if typeIdentifier.starts(with: HKQuantityTypeIdentifier_PREFIX) {
|
|
113
|
+
let identifier = HKQuantityTypeIdentifier.init(rawValue: typeIdentifier)
|
|
114
|
+
return HKObjectType.quantityType(forIdentifier: identifier) as HKObjectType?
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if typeIdentifier.starts(with: HKCategoryTypeIdentifier_PREFIX) {
|
|
118
|
+
let identifier = HKCategoryTypeIdentifier.init(rawValue: typeIdentifier)
|
|
119
|
+
return HKObjectType.categoryType(forIdentifier: identifier) as HKObjectType?
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if typeIdentifier.starts(with: HKCorrelationTypeIdentifier_PREFIX) {
|
|
123
|
+
let identifier = HKCorrelationTypeIdentifier.init(rawValue: typeIdentifier)
|
|
124
|
+
return HKObjectType.correlationType(forIdentifier: identifier) as HKObjectType?
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if typeIdentifier == HKActivitySummaryTypeIdentifier {
|
|
128
|
+
return HKObjectType.activitySummaryType()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if #available(iOS 13, *) {
|
|
132
|
+
if typeIdentifier == HKAudiogramTypeIdentifier {
|
|
133
|
+
return HKObjectType.audiogramSampleType()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if typeIdentifier == HKDataTypeIdentifierHeartbeatSeries {
|
|
137
|
+
return HKObjectType.seriesType(forIdentifier: typeIdentifier)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if typeIdentifier == HKWorkoutTypeIdentifier {
|
|
142
|
+
return HKObjectType.workoutType()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if #available(iOS 11.0, *) {
|
|
146
|
+
if typeIdentifier == HKWorkoutRouteTypeIdentifier {
|
|
147
|
+
return HKObjectType.seriesType(forIdentifier: typeIdentifier)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return nil
|
|
152
|
+
}
|
|
@@ -103,6 +103,13 @@ RCT_EXTERN_METHOD(queryHeartbeatSeriesSamples:(NSDate)from
|
|
|
103
103
|
to:(NSDate)to
|
|
104
104
|
limit:(NSInteger)limit
|
|
105
105
|
ascending:(BOOL)ascending
|
|
106
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
107
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
RCT_EXTERN_METHOD(queryHeartbeatSeriesSamplesWithAnchor:(NSDate)from
|
|
111
|
+
to:(NSDate)to
|
|
112
|
+
limit:(NSInteger)limit
|
|
106
113
|
anchor:(NSString)anchor
|
|
107
114
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
108
115
|
reject:(RCTPromiseRejectBlock)reject
|
|
@@ -113,6 +120,14 @@ RCT_EXTERN_METHOD(queryCategorySamples:(NSString)typeIdentifier
|
|
|
113
120
|
to:(NSDate)to
|
|
114
121
|
limit:(NSInteger)limit
|
|
115
122
|
ascending:(BOOL)ascending
|
|
123
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
124
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
RCT_EXTERN_METHOD(queryCategorySamplesWithAnchor:(NSString)typeIdentifier
|
|
128
|
+
from:(NSDate)from
|
|
129
|
+
to:(NSDate)to
|
|
130
|
+
limit:(NSInteger)limit
|
|
116
131
|
anchor:(NSString)anchor
|
|
117
132
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
118
133
|
reject:(RCTPromiseRejectBlock)reject
|
|
@@ -149,6 +164,15 @@ RCT_EXTERN_METHOD(queryQuantitySamples:(NSString)typeIdentifier
|
|
|
149
164
|
to:(NSDate)to
|
|
150
165
|
limit:(NSInteger)limit
|
|
151
166
|
ascending:(BOOL)ascending
|
|
167
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
168
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
RCT_EXTERN_METHOD(queryQuantitySamplesWithAnchor:(NSString)typeIdentifier
|
|
172
|
+
unitString:(NSString)unitString
|
|
173
|
+
from:(NSDate)from
|
|
174
|
+
to:(NSDate)to
|
|
175
|
+
limit:(NSInteger)limit
|
|
152
176
|
anchor:(NSString)anchor
|
|
153
177
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
154
178
|
reject:(RCTPromiseRejectBlock)reject
|