react-native-spike-sdk 2.3.0 → 2.3.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/README.md CHANGED
@@ -327,8 +327,10 @@ Under your project `Signing & Capabilities` section enable `Background Delivery`
327
327
  Call Spike configure methods on each app start to trigger background deliveries tasks.
328
328
  Add Spike initialization code to `ios/<Project Name>/AppDelegate.mm` file inside `application:didFinishLaunchingWithOptions:` method.
329
329
 
330
+ > If you plan on supporting background delivery, you need to set up all observer queries in your app delegate. Spike SDK will do it by calling `configure()` method. Read more [Receive Background Updates](https://developer.apple.com/documentation/healthkit/hkhealthstore/1614175-enablebackgrounddelivery#3801028).
331
+
330
332
  ```javascript
331
- #import <SpikeSDK/SpikeSDK-Swift.h>
333
+ import <SpikeSDK/SpikeSDK-Swift.h>
332
334
  ...
333
335
 
334
336
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
@@ -12,6 +12,7 @@ import com.spikeapi.SpikeConnection
12
12
  import com.spikeapi.SpikeExceptions
13
13
  import com.spikeapi.SpikeLogger
14
14
  import com.spikeapi.SpikePackageChecker
15
+ import com.spikeapi.healthconnect.HealthConnectAvailability
15
16
  import kotlinx.coroutines.CoroutineScope
16
17
  import kotlinx.coroutines.Dispatchers
17
18
  import kotlinx.coroutines.SupervisorJob
@@ -40,7 +41,7 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
40
41
  OffsetDateTime::class.java,
41
42
  OffsetDateTimeSerializer()
42
43
  ).create()
43
- private var checkPermissionsFor: Triple<String, String, Promise>? = null
44
+ private var checkPermissionsFor: Triple<String, Set<String>, Promise>? = null
44
45
 
45
46
  override fun getName(): String {
46
47
  return NAME
@@ -365,15 +366,20 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
365
366
  reactApplicationContext, permissions
366
367
  )
367
368
 
368
- reactApplicationContext.currentActivity?.startActivityForResult(
369
- intent,
370
- REQUEST_CODE
371
- )
372
- promise.resolve(true)
369
+ val availability = connection.getHealthConnectAvailability()
370
+ if (availability == HealthConnectAvailability.INSTALLED) {
371
+ reactApplicationContext.currentActivity?.startActivityForResult(
372
+ intent,
373
+ REQUEST_CODE
374
+ )
375
+ promise.resolve(true)
376
+ } else {
377
+ promise.reject(SpikeExceptions.SpikeException().mapException(), SpikeExceptions.SpikeException().message)
378
+ }
373
379
  } else {
374
380
  val activity = reactApplicationContext.currentActivity
375
381
  if (activity is ComponentActivity) {
376
- checkPermissionsFor = Triple(connectionUUID, dataType, promise)
382
+ checkPermissionsFor = Triple(connectionUUID, setOf(dataType), promise)
377
383
  val launcher =
378
384
  activity.registerActivityResultLauncher(
379
385
  SpikeConnection.requestReadAuthorization()
@@ -381,7 +387,11 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
381
387
 
382
388
  }
383
389
 
384
- launcher.launch(permissions)
390
+ if (permissions.isNotEmpty()) {
391
+ launcher.launch(permissions)
392
+ } else {
393
+ promise.resolve(false)
394
+ }
385
395
  } else {
386
396
  promise.resolve(false)
387
397
  }
@@ -404,15 +414,37 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
404
414
  }
405
415
 
406
416
  if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU) {
407
- val intent = SpikeConnection.requestReadAuthorization().createIntent(
408
- reactApplicationContext, permissions
409
- )
417
+ val availability = connection.getHealthConnectAvailability()
418
+ if (permissions.isNotEmpty() && availability == HealthConnectAvailability.INSTALLED) {
419
+ val intent = SpikeConnection.requestReadAuthorization().createIntent(
420
+ reactApplicationContext, permissions
421
+ )
410
422
 
411
- reactApplicationContext.currentActivity?.startActivityForResult(
412
- intent,
413
- REQUEST_CODE
414
- )
415
- promise.resolve(true)
423
+ reactApplicationContext.currentActivity?.startActivityForResult(
424
+ intent,
425
+ REQUEST_CODE
426
+ )
427
+ promise.resolve(true)
428
+ } else {
429
+ promise.reject(SpikeExceptions.SpikeException().mapException(), SpikeExceptions.SpikeException().message)
430
+ }
431
+ } else {
432
+ val activity = reactApplicationContext.currentActivity
433
+ if (activity is ComponentActivity) {
434
+ checkPermissionsFor = Triple(connectionUUID, dataTypes.toArrayList().toSet() as Set<String>, promise)
435
+ val launcher =
436
+ activity.registerActivityResultLauncher(
437
+ SpikeConnection.requestReadAuthorization()
438
+ ) {
439
+
440
+ }
441
+ if (permissions.isNotEmpty()) {
442
+ launcher.launch(permissions)
443
+ } else {
444
+ promise.reject(SpikeExceptions.SpikeException().mapException(), SpikeExceptions.SpikeException().message) }
445
+ } else {
446
+ promise.resolve(false)
447
+ }
416
448
  }
417
449
  }
418
450
 
@@ -452,11 +484,13 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
452
484
  }
453
485
  override fun onHostResume() {
454
486
  checkPermissionsFor?.let {
455
- checkPermissionsGranted(
456
- it.first,
457
- it.second,
458
- it.third
459
- )
487
+ it.second.forEach { permission ->
488
+ checkPermissionsGranted(
489
+ it.first,
490
+ permission,
491
+ it.third
492
+ )
493
+ }
460
494
  }
461
495
  checkPermissionsFor = null
462
496
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-spike-sdk",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "Spike API for health and productivity data from wearables and IoT devices",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -5,7 +5,7 @@ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1
5
5
 
6
6
  Pod::Spec.new do |s|
7
7
  s.name = "react-native-spike-sdk"
8
- s.version = "2.3.0"
8
+ s.version = "2.3.2"
9
9
  s.summary = "Spike API for health and productivity data from wearables and IoT devices"
10
10
 
11
11
  s.description = <<-DESC