@kingstinct/react-native-healthkit 9.0.7 → 9.0.9
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/CategoryTypeModule.swift +18 -21
- package/ios/CorrelationTypeModule.swift +18 -18
- package/ios/HeartbeatSeriesModule.swift +32 -32
- package/ios/QuantityTypeModule.swift +71 -59
- package/ios/Serializers.swift +12 -16
- package/ios/StateOfMindModule.swift +17 -17
- package/ios/WorkoutsModule.swift +59 -110
- package/lib/commonjs/healthkit.js +1 -1
- package/lib/module/healthkit.js +1 -1
- package/lib/typescript/healthkit.d.ts +3 -2
- package/lib/typescript/specs/WorkoutsModule.nitro.d.ts +3 -0
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.cpp +3 -44
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.hpp +24 -124
- package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Umbrella.hpp +0 -14
- package/package.json +2 -2
- package/src/healthkit.ts +2 -0
- package/src/specs/WorkoutsModule.nitro.ts +3 -0
- package/ios/WorkoutSessionModule.swift +0 -182
- package/lib/commonjs/specs/WorkoutSessionModule.nitro.js +0 -19
- package/lib/module/specs/WorkoutSessionModule.nitro.js +0 -16
- package/lib/typescript/specs/WorkoutSessionModule.nitro.d.ts +0 -47
- package/nitrogen/generated/ios/c++/HybridWorkoutSessionModuleSpecSwift.cpp +0 -11
- package/nitrogen/generated/ios/c++/HybridWorkoutSessionModuleSpecSwift.hpp +0 -107
- package/nitrogen/generated/ios/swift/Func_void_WorkoutEventType.swift +0 -46
- package/nitrogen/generated/ios/swift/Func_void_WorkoutSessionState_WorkoutSessionState_std__chrono__system_clock__time_point.swift +0 -46
- package/nitrogen/generated/ios/swift/Func_void_std__vector_RemoteSessionSharableData_.swift +0 -46
- package/nitrogen/generated/ios/swift/HybridWorkoutSessionModuleSpec.swift +0 -49
- package/nitrogen/generated/ios/swift/HybridWorkoutSessionModuleSpec_cxx.swift +0 -133
- package/nitrogen/generated/ios/swift/RemoteSessionSharableData.swift +0 -46
- package/nitrogen/generated/ios/swift/WorkoutSessionMirroringStartHandlerOptions.swift +0 -118
- package/nitrogen/generated/ios/swift/WorkoutSessionState.swift +0 -56
- package/nitrogen/generated/shared/c++/HybridWorkoutSessionModuleSpec.cpp +0 -22
- package/nitrogen/generated/shared/c++/HybridWorkoutSessionModuleSpec.hpp +0 -68
- package/nitrogen/generated/shared/c++/RemoteSessionSharableData.hpp +0 -75
- package/nitrogen/generated/shared/c++/WorkoutSessionMirroringStartHandlerOptions.hpp +0 -92
- package/nitrogen/generated/shared/c++/WorkoutSessionState.hpp +0 -68
- package/src/specs/WorkoutSessionModule.nitro.ts +0 -71
|
@@ -8,7 +8,7 @@ func queryQuantitySamplesInternal(
|
|
|
8
8
|
let quantityType = try initializeQuantityType(typeIdentifier.stringValue)
|
|
9
9
|
let predicate = try createPredicate(filter: options?.filter)
|
|
10
10
|
let limit = getQueryLimit(options?.limit)
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
return Promise.async {
|
|
13
13
|
let unit = try await getUnitToUse(unitOverride: options?.unit, quantityType: quantityType)
|
|
14
14
|
return try await withCheckedThrowingContinuation { continuation in
|
|
@@ -26,13 +26,13 @@ func queryQuantitySamplesInternal(
|
|
|
26
26
|
sample: sample,
|
|
27
27
|
unit: unit
|
|
28
28
|
)
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
return serialized
|
|
31
31
|
} catch {
|
|
32
32
|
print(error.localizedDescription)
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
return nil
|
|
37
37
|
}) {
|
|
38
38
|
return continuation.resume(returning: returnValue)
|
|
@@ -66,7 +66,7 @@ func saveQuantitySampleInternal(
|
|
|
66
66
|
end: end,
|
|
67
67
|
metadata: metadata
|
|
68
68
|
)
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
return Promise.async {
|
|
71
71
|
return try await withCheckedThrowingContinuation { continuation in
|
|
72
72
|
store.save(sample) { (success: Bool, error: Error?) in
|
|
@@ -80,39 +80,39 @@ func saveQuantitySampleInternal(
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
func getAnyMapValue(_ anyMap: AnyMapHolder, key: String) -> Any? {
|
|
83
|
-
if
|
|
83
|
+
if anyMap.isBool(key: key) {
|
|
84
84
|
return anyMap.getBoolean(key: key)
|
|
85
85
|
}
|
|
86
|
-
if
|
|
86
|
+
if anyMap.isArray(key: key) {
|
|
87
87
|
return anyMap.getArray(key: key)
|
|
88
88
|
}
|
|
89
|
-
if
|
|
89
|
+
if anyMap.isDouble(key: key) {
|
|
90
90
|
return anyMap.getDouble(key: key)
|
|
91
91
|
}
|
|
92
|
-
if
|
|
92
|
+
if anyMap.isObject(key: key) {
|
|
93
93
|
return anyMap.getObject(key: key)
|
|
94
94
|
}
|
|
95
|
-
if
|
|
95
|
+
if anyMap.isString(key: key) {
|
|
96
96
|
return anyMap.getString(key: key)
|
|
97
97
|
}
|
|
98
|
-
if
|
|
98
|
+
if anyMap.isBigInt(key: key) {
|
|
99
99
|
return anyMap.getBigInt(key: key)
|
|
100
100
|
}
|
|
101
|
-
if
|
|
101
|
+
if anyMap.isNull(key: key) {
|
|
102
102
|
return nil
|
|
103
103
|
}
|
|
104
104
|
return nil
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
func anyMapToDictionary(_ anyMap: AnyMapHolder) -> [String: Any] {
|
|
108
|
-
var dict =
|
|
108
|
+
var dict = [String: Any]()
|
|
109
109
|
anyMap.getAllKeys().forEach { key in
|
|
110
110
|
dict[key] = getAnyMapValue(anyMap, key: key)
|
|
111
111
|
}
|
|
112
112
|
return dict
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
func buildStatisticsOptions(statistics: [StatisticsOptions]) -> HKStatisticsOptions{
|
|
115
|
+
func buildStatisticsOptions(statistics: [StatisticsOptions]) -> HKStatisticsOptions {
|
|
116
116
|
// Build statistics options
|
|
117
117
|
var opts = HKStatisticsOptions()
|
|
118
118
|
for statistic in statistics {
|
|
@@ -140,11 +140,11 @@ func buildStatisticsOptions(statistics: [StatisticsOptions]) -> HKStatisticsOpti
|
|
|
140
140
|
return opts
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
class QuantityTypeModule
|
|
143
|
+
class QuantityTypeModule: HybridQuantityTypeModuleSpec {
|
|
144
144
|
func deleteQuantitySamples(identifier: QuantityTypeIdentifier, filter: FilterForSamples) throws -> Promise<Bool> {
|
|
145
145
|
let sampleType = try initializeQuantityType(identifier.stringValue)
|
|
146
146
|
let samplePredicate = try createPredicateForSamples(filter: filter)
|
|
147
|
-
|
|
147
|
+
|
|
148
148
|
return Promise.async {
|
|
149
149
|
return try await withCheckedThrowingContinuation { continuation in
|
|
150
150
|
store.deleteObjects(of: sampleType, predicate: samplePredicate) { (success: Bool, _: Int, error: Error?) in
|
|
@@ -156,21 +156,21 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
func isQuantityCompatibleWithUnit(identifier: QuantityTypeIdentifier, unit: String) throws -> Bool {
|
|
163
163
|
let sampleType = try initializeQuantityType(identifier.stringValue)
|
|
164
|
-
|
|
164
|
+
|
|
165
165
|
return sampleType.is(compatibleWith: HKUnit.init(from: unit))
|
|
166
166
|
}
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
func queryStatisticsForQuantity(identifier: QuantityTypeIdentifier, statistics: [StatisticsOptions], options: StatisticsQueryOptions?) throws -> Promise<QueryStatisticsResponse> {
|
|
169
|
-
|
|
169
|
+
|
|
170
170
|
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
171
171
|
let predicate = try createPredicate(filter: options?.filter)
|
|
172
172
|
let unit = HKUnit.init(from: options?.unit ?? "count")
|
|
173
|
-
|
|
173
|
+
|
|
174
174
|
return Promise.async {
|
|
175
175
|
return try await withCheckedThrowingContinuation { continuation in
|
|
176
176
|
let query = HKStatisticsQuery.init(
|
|
@@ -182,15 +182,15 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
182
182
|
continuation.resume(throwing: error)
|
|
183
183
|
return
|
|
184
184
|
}
|
|
185
|
-
|
|
185
|
+
|
|
186
186
|
guard let gottenStats = stats else {
|
|
187
187
|
let emptyResponse = QueryStatisticsResponse()
|
|
188
188
|
continuation.resume(returning: emptyResponse)
|
|
189
189
|
return
|
|
190
190
|
}
|
|
191
|
-
|
|
191
|
+
|
|
192
192
|
var response = QueryStatisticsResponse()
|
|
193
|
-
|
|
193
|
+
|
|
194
194
|
if let averageQuantity = gottenStats.averageQuantity() {
|
|
195
195
|
response.averageQuantity = Quantity(
|
|
196
196
|
unit: unit.unitString,
|
|
@@ -215,7 +215,7 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
215
215
|
quantity: sumQuantity.doubleValue(for: unit)
|
|
216
216
|
)
|
|
217
217
|
}
|
|
218
|
-
|
|
218
|
+
|
|
219
219
|
if #available(iOS 12, *) {
|
|
220
220
|
if let mostRecent = gottenStats.mostRecentQuantity() {
|
|
221
221
|
response.mostRecentQuantity = Quantity(
|
|
@@ -223,7 +223,7 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
223
223
|
quantity: mostRecent.doubleValue(for: unit)
|
|
224
224
|
)
|
|
225
225
|
}
|
|
226
|
-
|
|
226
|
+
|
|
227
227
|
if let mostRecentDateInterval = gottenStats.mostRecentQuantityDateInterval() {
|
|
228
228
|
response.mostRecentQuantityDateInterval = QuantityDateInterval(
|
|
229
229
|
from: mostRecentDateInterval.start,
|
|
@@ -231,7 +231,7 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
231
231
|
)
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
|
|
235
235
|
if #available(iOS 13, *) {
|
|
236
236
|
if let duration = gottenStats.duration() {
|
|
237
237
|
let durationUnit = HKUnit.second()
|
|
@@ -241,27 +241,27 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
241
241
|
)
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
-
|
|
244
|
+
|
|
245
245
|
continuation.resume(returning: response)
|
|
246
246
|
}
|
|
247
|
-
|
|
247
|
+
|
|
248
248
|
store.execute(query)
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
|
|
252
|
+
|
|
253
253
|
func queryStatisticsCollectionForQuantity(identifier: QuantityTypeIdentifier, statistics: [StatisticsOptions], anchorDate: String, intervalComponents: IntervalComponents, options: StatisticsQueryOptions?) throws -> Promise<[QueryStatisticsResponse]> {
|
|
254
254
|
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
255
|
-
|
|
255
|
+
|
|
256
256
|
let predicate = try createPredicate(filter: options?.filter)
|
|
257
257
|
let unit = HKUnit.init(from: options?.unit ?? "count")
|
|
258
|
-
|
|
258
|
+
|
|
259
259
|
// Convert the anchor date string to Date
|
|
260
260
|
let dateFormatter = ISO8601DateFormatter()
|
|
261
261
|
guard let anchor = dateFormatter.date(from: anchorDate) else {
|
|
262
262
|
throw RuntimeError.error(withMessage: "Invalid anchor date format: " + anchorDate)
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
// Create date components from interval
|
|
266
266
|
var dateComponents = DateComponents()
|
|
267
267
|
if let minute = intervalComponents.minute {
|
|
@@ -279,10 +279,10 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
279
279
|
if let year = intervalComponents.year {
|
|
280
280
|
dateComponents.year = Int(year)
|
|
281
281
|
}
|
|
282
|
-
|
|
282
|
+
|
|
283
283
|
// Build statistics options
|
|
284
284
|
let opts = buildStatisticsOptions(statistics: statistics)
|
|
285
|
-
|
|
285
|
+
|
|
286
286
|
return Promise.async {
|
|
287
287
|
return try await withCheckedThrowingContinuation { continuation in
|
|
288
288
|
let query = HKStatisticsCollectionQuery.init(
|
|
@@ -292,24 +292,37 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
292
292
|
anchorDate: anchor,
|
|
293
293
|
intervalComponents: dateComponents
|
|
294
294
|
)
|
|
295
|
-
|
|
295
|
+
|
|
296
296
|
query.initialResultsHandler = { (_, results: HKStatisticsCollection?, error: Error?) in
|
|
297
297
|
if let error = error {
|
|
298
298
|
continuation.resume(throwing: error)
|
|
299
299
|
return
|
|
300
300
|
}
|
|
301
|
-
|
|
301
|
+
|
|
302
302
|
guard let statistics = results else {
|
|
303
303
|
continuation.resume(returning: [])
|
|
304
304
|
return
|
|
305
305
|
}
|
|
306
|
-
|
|
306
|
+
|
|
307
307
|
var responseArray: [QueryStatisticsResponse] = []
|
|
308
|
-
|
|
309
|
-
//
|
|
310
|
-
|
|
308
|
+
|
|
309
|
+
// Limit enumeration to the range in the provided filter if possible
|
|
310
|
+
var enumerateFrom = Date.distantPast
|
|
311
|
+
var enumerateTo = Date()
|
|
312
|
+
|
|
313
|
+
if let filter = options?.filter {
|
|
314
|
+
switch filter {
|
|
315
|
+
case .fourth(let dateFilter):
|
|
316
|
+
enumerateFrom = dateFilter.startDate ?? enumerateFrom
|
|
317
|
+
enumerateTo = dateFilter.endDate ?? enumerateTo
|
|
318
|
+
default:
|
|
319
|
+
break
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
statistics.enumerateStatistics(from: enumerateFrom, to: enumerateTo) { stats, _ in
|
|
311
324
|
var response = QueryStatisticsResponse()
|
|
312
|
-
|
|
325
|
+
|
|
313
326
|
if let averageQuantity = stats.averageQuantity() {
|
|
314
327
|
response.averageQuantity = Quantity(
|
|
315
328
|
unit: unit.unitString,
|
|
@@ -334,7 +347,7 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
334
347
|
quantity: sumQuantity.doubleValue(for: unit)
|
|
335
348
|
)
|
|
336
349
|
}
|
|
337
|
-
|
|
350
|
+
|
|
338
351
|
if #available(iOS 12, *) {
|
|
339
352
|
if let mostRecent = stats.mostRecentQuantity() {
|
|
340
353
|
response.mostRecentQuantity = Quantity(
|
|
@@ -342,7 +355,7 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
342
355
|
quantity: mostRecent.doubleValue(for: unit)
|
|
343
356
|
)
|
|
344
357
|
}
|
|
345
|
-
|
|
358
|
+
|
|
346
359
|
if let mostRecentDateInterval = stats.mostRecentQuantityDateInterval() {
|
|
347
360
|
response.mostRecentQuantityDateInterval = QuantityDateInterval(
|
|
348
361
|
from: mostRecentDateInterval.start,
|
|
@@ -350,7 +363,7 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
350
363
|
)
|
|
351
364
|
}
|
|
352
365
|
}
|
|
353
|
-
|
|
366
|
+
|
|
354
367
|
if #available(iOS 13, *) {
|
|
355
368
|
if let duration = stats.duration() {
|
|
356
369
|
let durationUnit = HKUnit.second()
|
|
@@ -360,30 +373,30 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
360
373
|
)
|
|
361
374
|
}
|
|
362
375
|
}
|
|
363
|
-
|
|
376
|
+
|
|
364
377
|
responseArray.append(response)
|
|
365
378
|
}
|
|
366
|
-
|
|
379
|
+
|
|
367
380
|
continuation.resume(returning: responseArray)
|
|
368
381
|
}
|
|
369
|
-
|
|
382
|
+
|
|
370
383
|
store.execute(query)
|
|
371
384
|
}
|
|
372
385
|
}
|
|
373
386
|
}
|
|
374
|
-
|
|
387
|
+
|
|
375
388
|
func queryQuantitySamplesWithAnchor(identifier: QuantityTypeIdentifier, options: QueryOptionsWithAnchorAndUnit) throws -> Promise<QuantitySamplesWithAnchorResponse> {
|
|
376
389
|
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
377
390
|
let predicate = try createPredicate(filter: options.filter)
|
|
378
391
|
let limit = getQueryLimit(options.limit)
|
|
379
392
|
let actualAnchor = try deserializeHKQueryAnchor(base64String: options.anchor)
|
|
380
|
-
|
|
393
|
+
|
|
381
394
|
return Promise.async {
|
|
382
395
|
let unit = try await getUnitToUse(
|
|
383
396
|
unitOverride: options.unit,
|
|
384
397
|
quantityType: quantityType
|
|
385
398
|
)
|
|
386
|
-
|
|
399
|
+
|
|
387
400
|
return try await withCheckedThrowingContinuation { continuation in
|
|
388
401
|
let query = HKAnchoredObjectQuery(
|
|
389
402
|
type: quantityType,
|
|
@@ -401,7 +414,7 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
401
414
|
continuation.resume(throwing: error)
|
|
402
415
|
return
|
|
403
416
|
}
|
|
404
|
-
|
|
417
|
+
|
|
405
418
|
guard let samples = samples else {
|
|
406
419
|
let response = QuantitySamplesWithAnchorResponse(
|
|
407
420
|
samples: [],
|
|
@@ -411,7 +424,7 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
411
424
|
continuation.resume(returning: response)
|
|
412
425
|
return
|
|
413
426
|
}
|
|
414
|
-
|
|
427
|
+
|
|
415
428
|
let quantitySamples = samples.compactMap { sample in
|
|
416
429
|
if let quantitySample = sample as? HKQuantitySample {
|
|
417
430
|
do {
|
|
@@ -425,21 +438,21 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
425
438
|
}
|
|
426
439
|
return nil
|
|
427
440
|
}
|
|
428
|
-
|
|
441
|
+
|
|
429
442
|
let response = QuantitySamplesWithAnchorResponse(
|
|
430
443
|
samples: quantitySamples,
|
|
431
444
|
deletedSamples: deletedSamples?.map { serializeDeletedSample(sample: $0) } ?? [],
|
|
432
445
|
newAnchor: serializeAnchor(anchor: newAnchor) ?? ""
|
|
433
446
|
)
|
|
434
|
-
|
|
447
|
+
|
|
435
448
|
continuation.resume(returning: response)
|
|
436
449
|
}
|
|
437
|
-
|
|
450
|
+
|
|
438
451
|
store.execute(query)
|
|
439
452
|
}
|
|
440
453
|
}
|
|
441
454
|
}
|
|
442
|
-
|
|
455
|
+
|
|
443
456
|
func saveQuantitySample(identifier: QuantityTypeIdentifier, unit: String, value: Double, start: Date, end: Date, metadata: AnyMapHolder) throws -> Promise<Bool> {
|
|
444
457
|
return saveQuantitySampleInternal(
|
|
445
458
|
typeIdentifier: HKQuantityType(
|
|
@@ -456,6 +469,5 @@ class QuantityTypeModule : HybridQuantityTypeModuleSpec {
|
|
|
456
469
|
func queryQuantitySamples(identifier: QuantityTypeIdentifier, options: QueryOptionsWithSortOrderAndUnit?) throws -> Promise<[QuantitySample]> {
|
|
457
470
|
return try queryQuantitySamplesInternal(typeIdentifier: identifier, options: options)
|
|
458
471
|
}
|
|
459
|
-
|
|
460
|
-
|
|
472
|
+
|
|
461
473
|
}
|
package/ios/Serializers.swift
CHANGED
|
@@ -13,7 +13,7 @@ func serializeQuantityTyped(unit: HKUnit, quantityNullable: HKQuantity?) -> Quan
|
|
|
13
13
|
guard let q = quantityNullable else {
|
|
14
14
|
return nil
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
return Quantity(
|
|
18
18
|
unit: unit.unitString,
|
|
19
19
|
quantity: q.doubleValue(for: unit)
|
|
@@ -38,7 +38,7 @@ func serializeQuantitySample(sample: HKQuantitySample, unit: HKUnit) throws -> Q
|
|
|
38
38
|
quantity: sample.quantity.doubleValue(for: unit),
|
|
39
39
|
unit: unit.unitString,
|
|
40
40
|
metadata: serializeMetadata(sample.metadata),
|
|
41
|
-
sourceRevision: serializeSourceRevision(sample.sourceRevision)
|
|
41
|
+
sourceRevision: serializeSourceRevision(sample.sourceRevision)
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
44
|
throw RuntimeError.error(withMessage: "[react-native-healthkit] Unable to recognize quantityType: \(sample.quantityType.identifier)")
|
|
@@ -51,7 +51,6 @@ func serializeDeletedSample(sample: HKDeletedObject) -> DeletedSample {
|
|
|
51
51
|
)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
54
|
func serializeCategorySample(sample: HKCategorySample) -> CategorySample {
|
|
56
55
|
return CategorySample(
|
|
57
56
|
uuid: sample.uuid.uuidString,
|
|
@@ -71,7 +70,6 @@ func serializeSource(_ source: HKSource) -> SourceProxy {
|
|
|
71
70
|
)
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
|
|
75
73
|
func getUnitForQuantityType(quantityType: HKQuantityType) -> HKUnit? {
|
|
76
74
|
if quantityType.is(compatibleWith: HKUnit.percent()) {
|
|
77
75
|
return HKUnit.percent()
|
|
@@ -92,7 +90,7 @@ func getUnitForQuantityType(quantityType: HKQuantityType) -> HKUnit? {
|
|
|
92
90
|
if quantityType.is(compatibleWith: HKUnit.meter()) {
|
|
93
91
|
return HKUnit.meter()
|
|
94
92
|
}
|
|
95
|
-
|
|
93
|
+
|
|
96
94
|
if quantityType.is(compatibleWith: SpeedUnit) {
|
|
97
95
|
return SpeedUnit
|
|
98
96
|
}
|
|
@@ -130,7 +128,6 @@ func getUnitForQuantityType(quantityType: HKQuantityType) -> HKUnit? {
|
|
|
130
128
|
}
|
|
131
129
|
#endif
|
|
132
130
|
|
|
133
|
-
|
|
134
131
|
return nil
|
|
135
132
|
}
|
|
136
133
|
|
|
@@ -138,7 +135,7 @@ func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
|
|
|
138
135
|
guard let quantity = quantity else {
|
|
139
136
|
return nil
|
|
140
137
|
}
|
|
141
|
-
|
|
138
|
+
|
|
142
139
|
if quantity.is(compatibleWith: HKUnit.percent()) {
|
|
143
140
|
return serializeQuantityTyped(unit: HKUnit.percent(), quantity: quantity)
|
|
144
141
|
}
|
|
@@ -199,14 +196,14 @@ func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
|
|
|
199
196
|
return nil
|
|
200
197
|
}
|
|
201
198
|
|
|
202
|
-
func serializeUnknownQuantity(quantity: HKQuantity) ->
|
|
199
|
+
func serializeUnknownQuantity(quantity: HKQuantity) -> [String: AnyValue]? {
|
|
203
200
|
if let quantityTyped = serializeUnknownQuantityTyped(quantity: quantity) {
|
|
204
201
|
return [
|
|
205
202
|
"quantity": AnyValue.number(quantityTyped.quantity),
|
|
206
203
|
"unit": AnyValue.string(quantityTyped.unit)
|
|
207
204
|
]
|
|
208
205
|
}
|
|
209
|
-
|
|
206
|
+
|
|
210
207
|
return nil
|
|
211
208
|
}
|
|
212
209
|
|
|
@@ -217,7 +214,7 @@ func serializeMetadata(_ metadata: [String: Any]?) -> AnyMapHolder {
|
|
|
217
214
|
if let bool = item.value as? Bool {
|
|
218
215
|
serialized.setBoolean(key: item.key, value: bool)
|
|
219
216
|
}
|
|
220
|
-
|
|
217
|
+
|
|
221
218
|
if let str = item.value as? String {
|
|
222
219
|
serialized.setString(key: item.key, value: str)
|
|
223
220
|
}
|
|
@@ -225,14 +222,14 @@ func serializeMetadata(_ metadata: [String: Any]?) -> AnyMapHolder {
|
|
|
225
222
|
if let double = item.value as? Double {
|
|
226
223
|
serialized.setDouble(key: item.key, value: double)
|
|
227
224
|
}
|
|
228
|
-
|
|
225
|
+
|
|
229
226
|
if let quantity = item.value as? HKQuantity {
|
|
230
227
|
if let s = serializeUnknownQuantity(quantity: quantity) {
|
|
231
228
|
serialized.setObject(key: item.key, value: s)
|
|
232
229
|
}
|
|
233
230
|
}
|
|
234
|
-
|
|
235
|
-
if let dict = item.value as?
|
|
231
|
+
|
|
232
|
+
if let dict = item.value as? [String: AnyValue] {
|
|
236
233
|
serialized.setObject(key: item.key, value: dict)
|
|
237
234
|
}
|
|
238
235
|
}
|
|
@@ -267,7 +264,7 @@ func serializeDevice(hkDevice: HKDevice?) -> Device? {
|
|
|
267
264
|
guard let hkDevice = hkDevice else {
|
|
268
265
|
return nil
|
|
269
266
|
}
|
|
270
|
-
|
|
267
|
+
|
|
271
268
|
return Device(
|
|
272
269
|
name: hkDevice.name,
|
|
273
270
|
firmwareVersion: hkDevice.firmwareVersion,
|
|
@@ -295,7 +292,6 @@ func serializeSourceRevision(_ hkSourceRevision: HKSourceRevision?) -> SourceRev
|
|
|
295
292
|
return nil
|
|
296
293
|
}
|
|
297
294
|
|
|
298
|
-
|
|
299
295
|
if #available(iOS 11, *) {
|
|
300
296
|
return SourceRevision(
|
|
301
297
|
source: serializeSource(hkSourceRevision.source),
|
|
@@ -304,7 +300,7 @@ func serializeSourceRevision(_ hkSourceRevision: HKSourceRevision?) -> SourceRev
|
|
|
304
300
|
productType: hkSourceRevision.productType
|
|
305
301
|
)
|
|
306
302
|
}
|
|
307
|
-
|
|
303
|
+
|
|
308
304
|
return SourceRevision(
|
|
309
305
|
source: serializeSource(hkSourceRevision.source),
|
|
310
306
|
version: hkSourceRevision.version,
|
|
@@ -9,20 +9,20 @@ func serializeStateOfMindSample(sample: HKStateOfMind) -> StateOfMindSample {
|
|
|
9
9
|
return association
|
|
10
10
|
}
|
|
11
11
|
print("[react-native-healthkit] Unknown StateOfMindAssociation raw value: \(association.rawValue)")
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
return nil
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
// todo: warn if we get unknown labels??
|
|
17
17
|
let labels = sample.labels.compactMap { label in
|
|
18
|
-
if let label = StateOfMindLabel(rawValue: Int32(label.rawValue)){
|
|
18
|
+
if let label = StateOfMindLabel(rawValue: Int32(label.rawValue)) {
|
|
19
19
|
return label
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
print("[react-native-healthkit] Unknown StateOfMindLabel raw value: \(label.rawValue)")
|
|
23
23
|
return nil
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
return StateOfMindSample(
|
|
27
27
|
uuid: sample.uuid.uuidString,
|
|
28
28
|
device: serializeDevice(hkDevice: sample.device),
|
|
@@ -41,18 +41,18 @@ func serializeStateOfMindSample(sample: HKStateOfMind) -> StateOfMindSample {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
#if compiler(>=6)
|
|
44
|
-
class StateOfMindModule
|
|
44
|
+
class StateOfMindModule: HybridStateOfMindModuleSpec {
|
|
45
45
|
func queryStateOfMindSamples(
|
|
46
46
|
options: QueryOptionsWithSortOrder?
|
|
47
47
|
) throws -> Promise<[StateOfMindSample]> {
|
|
48
48
|
if #available(iOS 18.0, *) {
|
|
49
49
|
let predicate = try createPredicate(filter: options?.filter)
|
|
50
50
|
let queryLimit = getQueryLimit(options?.limit)
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
return Promise.async {
|
|
53
53
|
try await withCheckedThrowingContinuation { continuation in
|
|
54
54
|
let type = HKStateOfMindType.stateOfMindType()
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
let query = HKSampleQuery(
|
|
57
57
|
sampleType: type,
|
|
58
58
|
predicate: predicate,
|
|
@@ -65,18 +65,18 @@ class StateOfMindModule : HybridStateOfMindModuleSpec {
|
|
|
65
65
|
continuation.resume(throwing: error)
|
|
66
66
|
return
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
guard let samples = samples as? [HKStateOfMind] else {
|
|
70
70
|
return continuation.resume(throwing: RuntimeError.error(withMessage: "[react-native-healthkit] Unexpected empty response"))
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
let serializedSamples = samples.map { sample -> StateOfMindSample in
|
|
74
74
|
return serializeStateOfMindSample(sample: sample)
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
continuation.resume(returning: serializedSamples)
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
store.execute(query)
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -84,7 +84,7 @@ class StateOfMindModule : HybridStateOfMindModuleSpec {
|
|
|
84
84
|
throw RuntimeError.error(withMessage: "StateOfMind is only available on iOS 18 and later")
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
func saveStateOfMindSample(
|
|
89
89
|
date: Date,
|
|
90
90
|
kind: StateOfMindKind,
|
|
@@ -112,7 +112,7 @@ class StateOfMindModule : HybridStateOfMindModuleSpec {
|
|
|
112
112
|
print("[react-native-healthkit] Unknown StateOfMindAssociation raw value: \($0.rawValue)")
|
|
113
113
|
return nil
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
let sample = HKStateOfMind(
|
|
117
117
|
date: date,
|
|
118
118
|
kind: hkKind,
|
|
@@ -121,7 +121,7 @@ class StateOfMindModule : HybridStateOfMindModuleSpec {
|
|
|
121
121
|
associations: hkAssociations,
|
|
122
122
|
metadata: anyMapToDictionary(metadata ?? AnyMapHolder())
|
|
123
123
|
)
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
store.save(sample) { (success: Bool, error: Error?) in
|
|
126
126
|
if let error = error {
|
|
127
127
|
continuation.resume(throwing: error)
|
|
@@ -139,13 +139,13 @@ class StateOfMindModule : HybridStateOfMindModuleSpec {
|
|
|
139
139
|
}
|
|
140
140
|
#else
|
|
141
141
|
// Fallback for older Xcode versions
|
|
142
|
-
class StateOfMind
|
|
142
|
+
class StateOfMind: HybridStateOfMindModuleSpec {
|
|
143
143
|
func queryStateOfMindSamples(
|
|
144
144
|
options: QueryOptionsWithSortOrder?
|
|
145
145
|
) throws -> Promise<[StateOfMindSample]> {
|
|
146
146
|
throw RuntimeError.error(withMessage: "State of Mind features require iOS 18.0 or later and Xcode 16 or later to compile")
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
|
|
149
149
|
func saveStateOfMindSample(
|
|
150
150
|
date: Date,
|
|
151
151
|
kind: StateOfMindKind,
|