@kingstinct/react-native-healthkit 13.0.1 → 13.0.2
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/QuantityTypeModule.swift +53 -42
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import HealthKit
|
|
2
2
|
import NitroModules
|
|
3
3
|
|
|
4
|
-
func emptyStatisticsResponse(from: Date
|
|
4
|
+
func emptyStatisticsResponse(from: Date?, to: Date?) -> QueryStatisticsResponse {
|
|
5
5
|
var response = QueryStatisticsResponse()
|
|
6
6
|
|
|
7
7
|
response.startDate = from
|
|
8
8
|
response.endDate = to
|
|
9
|
+
response.sources = []
|
|
9
10
|
|
|
10
11
|
return response
|
|
11
12
|
}
|
|
@@ -14,7 +15,7 @@ func queryStatisticsForQuantityInternal(
|
|
|
14
15
|
quantityType: HKQuantityType,
|
|
15
16
|
statistics: [StatisticsOptions],
|
|
16
17
|
options: StatisticsQueryOptions?
|
|
17
|
-
) async throws -> HKStatistics {
|
|
18
|
+
) async throws -> HKStatistics? {
|
|
18
19
|
let predicate = createPredicateForSamples(options?.filter)
|
|
19
20
|
|
|
20
21
|
return try await withCheckedThrowingContinuation { continuation in
|
|
@@ -25,7 +26,9 @@ func queryStatisticsForQuantityInternal(
|
|
|
25
26
|
) { (_, stats: HKStatistics?, error: Error?) in
|
|
26
27
|
DispatchQueue.main.async {
|
|
27
28
|
if let error = error {
|
|
28
|
-
return
|
|
29
|
+
return handleHKNoDataOrThrow(error: error, continuation: continuation, noDataFallback: {
|
|
30
|
+
return nil
|
|
31
|
+
})
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
if let stats = stats {
|
|
@@ -113,7 +116,7 @@ func queryStatisticsCollectionForQuantityInternal(
|
|
|
113
116
|
anchorDate: Date,
|
|
114
117
|
intervalComponents: IntervalComponents,
|
|
115
118
|
options: StatisticsQueryOptions?
|
|
116
|
-
) async throws -> HKStatisticsCollection {
|
|
119
|
+
) async throws -> HKStatisticsCollection? {
|
|
117
120
|
let predicate = createPredicateForSamples(options?.filter)
|
|
118
121
|
|
|
119
122
|
// Create date components from interval
|
|
@@ -148,7 +151,9 @@ func queryStatisticsCollectionForQuantityInternal(
|
|
|
148
151
|
|
|
149
152
|
query.initialResultsHandler = { (_, results: HKStatisticsCollection?, error: Error?) in
|
|
150
153
|
if let error = error {
|
|
151
|
-
return
|
|
154
|
+
return handleHKNoDataOrThrow(error: error, continuation: continuation, noDataFallback: {
|
|
155
|
+
return nil
|
|
156
|
+
})
|
|
152
157
|
}
|
|
153
158
|
|
|
154
159
|
guard let statistics = results else {
|
|
@@ -280,20 +285,19 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
|
|
|
280
285
|
return Promise.async {
|
|
281
286
|
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
282
287
|
|
|
283
|
-
let gottenStats = try await queryStatisticsForQuantityInternal(
|
|
288
|
+
if let gottenStats = try await queryStatisticsForQuantityInternal(
|
|
284
289
|
quantityType: quantityType,
|
|
285
290
|
statistics: statistics,
|
|
286
291
|
options: options
|
|
287
|
-
)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return response
|
|
292
|
+
) {
|
|
293
|
+
let unit = try await getUnitToUse(
|
|
294
|
+
unitOverride: options?.unit,
|
|
295
|
+
quantityType: quantityType
|
|
296
|
+
)
|
|
297
|
+
return serializeStatisticsPerSource(gottenStats: gottenStats, unit: unit)
|
|
298
|
+
} else {
|
|
299
|
+
return []
|
|
300
|
+
}
|
|
297
301
|
}
|
|
298
302
|
}
|
|
299
303
|
|
|
@@ -304,22 +308,24 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
|
|
|
304
308
|
return Promise.async {
|
|
305
309
|
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
306
310
|
|
|
307
|
-
let statistics = try await queryStatisticsCollectionForQuantityInternal(
|
|
311
|
+
if let statistics = try await queryStatisticsCollectionForQuantityInternal(
|
|
308
312
|
quantityType: quantityType,
|
|
309
313
|
statistics: statistics,
|
|
310
314
|
anchorDate: anchorDate,
|
|
311
315
|
intervalComponents: intervalComponents,
|
|
312
316
|
options: options
|
|
313
|
-
)
|
|
317
|
+
) {
|
|
314
318
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
+
let unit = try await getUnitToUse(
|
|
320
|
+
unitOverride: options?.unit,
|
|
321
|
+
quantityType: quantityType
|
|
322
|
+
)
|
|
319
323
|
|
|
320
|
-
|
|
321
|
-
|
|
324
|
+
return statistics.statistics().flatMap { statistics in
|
|
325
|
+
return serializeStatisticsPerSource(gottenStats: statistics, unit: unit)
|
|
326
|
+
}
|
|
322
327
|
}
|
|
328
|
+
return []
|
|
323
329
|
}
|
|
324
330
|
}
|
|
325
331
|
|
|
@@ -351,20 +357,23 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
|
|
|
351
357
|
return Promise.async {
|
|
352
358
|
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
353
359
|
|
|
354
|
-
let gottenStats = try await queryStatisticsForQuantityInternal(
|
|
360
|
+
if let gottenStats = try await queryStatisticsForQuantityInternal(
|
|
355
361
|
quantityType: quantityType,
|
|
356
362
|
statistics: statistics,
|
|
357
363
|
options: options
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
)
|
|
364
|
+
) {
|
|
365
|
+
let unit = try await getUnitToUse(
|
|
366
|
+
unitOverride: options?.unit,
|
|
367
|
+
quantityType: quantityType
|
|
368
|
+
)
|
|
364
369
|
|
|
365
|
-
|
|
370
|
+
return serializeStatistics(gottenStats: gottenStats, unit: unit)
|
|
371
|
+
}
|
|
366
372
|
|
|
367
|
-
return
|
|
373
|
+
return emptyStatisticsResponse(
|
|
374
|
+
from: options?.filter?.date?.startDate,
|
|
375
|
+
to: options?.filter?.date?.endDate
|
|
376
|
+
)
|
|
368
377
|
}
|
|
369
378
|
}
|
|
370
379
|
|
|
@@ -375,22 +384,24 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
|
|
|
375
384
|
return Promise.async {
|
|
376
385
|
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
377
386
|
|
|
378
|
-
let statistics = try await queryStatisticsCollectionForQuantityInternal(
|
|
387
|
+
if let statistics = try await queryStatisticsCollectionForQuantityInternal(
|
|
379
388
|
quantityType: quantityType,
|
|
380
389
|
statistics: statistics,
|
|
381
390
|
anchorDate: anchorDate,
|
|
382
391
|
intervalComponents: intervalComponents,
|
|
383
392
|
options: options
|
|
384
|
-
)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
)
|
|
393
|
+
) {
|
|
394
|
+
let unit = try await getUnitToUse(
|
|
395
|
+
unitOverride: options?.unit,
|
|
396
|
+
quantityType: quantityType
|
|
397
|
+
)
|
|
390
398
|
|
|
391
|
-
|
|
392
|
-
|
|
399
|
+
return statistics.statistics().map { statistics in
|
|
400
|
+
return serializeStatistics(gottenStats: statistics, unit: unit)
|
|
401
|
+
}
|
|
393
402
|
}
|
|
403
|
+
|
|
404
|
+
return []
|
|
394
405
|
}
|
|
395
406
|
}
|
|
396
407
|
|