react-native-background-geolocation 4.1.0 → 4.4.0

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/android/build.gradle +7 -10
  3. package/android/libs/com/transistorsoft/tslocationmanager/{3.1.28/tslocationmanager-3.1.28.aar → 3.1.34/tslocationmanager-3.1.34.aar} +0 -0
  4. package/android/libs/com/transistorsoft/tslocationmanager/3.1.34/tslocationmanager-3.1.34.aar.md5 +1 -0
  5. package/android/libs/com/transistorsoft/tslocationmanager/3.1.34/tslocationmanager-3.1.34.aar.sha1 +1 -0
  6. package/android/libs/com/transistorsoft/tslocationmanager/3.1.34/tslocationmanager-3.1.34.aar.sha256 +1 -0
  7. package/android/libs/com/transistorsoft/tslocationmanager/3.1.34/tslocationmanager-3.1.34.aar.sha512 +1 -0
  8. package/android/libs/com/transistorsoft/tslocationmanager/{3.1.28/tslocationmanager-3.1.28.pom → 3.1.34/tslocationmanager-3.1.34.pom} +1 -1
  9. package/android/libs/com/transistorsoft/tslocationmanager/3.1.34/tslocationmanager-3.1.34.pom.md5 +1 -0
  10. package/android/libs/com/transistorsoft/tslocationmanager/3.1.34/tslocationmanager-3.1.34.pom.sha1 +1 -0
  11. package/android/libs/com/transistorsoft/tslocationmanager/3.1.34/tslocationmanager-3.1.34.pom.sha256 +1 -0
  12. package/android/libs/com/transistorsoft/tslocationmanager/3.1.34/tslocationmanager-3.1.34.pom.sha512 +1 -0
  13. package/android/libs/com/transistorsoft/tslocationmanager/maven-metadata.xml +6 -12
  14. package/android/libs/com/transistorsoft/tslocationmanager-reverse/{3.1.28/tslocationmanager-reverse-3.1.28.aar → 3.1.34/tslocationmanager-reverse-3.1.34.aar} +0 -0
  15. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.34/tslocationmanager-reverse-3.1.34.aar.md5 +1 -0
  16. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.34/tslocationmanager-reverse-3.1.34.aar.sha1 +1 -0
  17. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.34/tslocationmanager-reverse-3.1.34.aar.sha256 +1 -0
  18. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.34/tslocationmanager-reverse-3.1.34.aar.sha512 +1 -0
  19. package/android/libs/com/transistorsoft/tslocationmanager-reverse/{3.1.28/tslocationmanager-reverse-3.1.28.pom → 3.1.34/tslocationmanager-reverse-3.1.34.pom} +1 -1
  20. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.34/tslocationmanager-reverse-3.1.34.pom.md5 +1 -0
  21. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.34/tslocationmanager-reverse-3.1.34.pom.sha1 +1 -0
  22. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.34/tslocationmanager-reverse-3.1.34.pom.sha256 +1 -0
  23. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.34/tslocationmanager-reverse-3.1.34.pom.sha512 +1 -0
  24. package/android/libs/com/transistorsoft/tslocationmanager-reverse/maven-metadata.xml +6 -11
  25. package/android/src/main/java/com/transistorsoft/rnbackgroundgeolocation/RNBackgroundGeolocationModule.java +41 -79
  26. package/ios/RNBackgroundGeolocation/RNBackgroundGeolocation.m +60 -136
  27. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/Info.plist +9 -9
  28. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_armv7/TSLocationManager.framework/Info.plist +0 -0
  29. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_armv7/TSLocationManager.framework/TSLocationManager +0 -0
  30. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_i386_x86_64-simulator/TSLocationManager.framework/Info.plist +0 -0
  31. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_i386_x86_64-simulator/TSLocationManager.framework/TSLocationManager +0 -0
  32. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_i386_x86_64-simulator/TSLocationManager.framework/_CodeSignature/CodeDirectory +0 -0
  33. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_i386_x86_64-simulator/TSLocationManager.framework/_CodeSignature/CodeRequirements-1 +0 -0
  34. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_i386_x86_64-simulator/TSLocationManager.framework/_CodeSignature/CodeResources +1 -1
  35. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_x86_64-maccatalyst/TSLocationManager.framework/Resources/Info.plist +9 -9
  36. package/ios/RNBackgroundGeolocation/TSLocationManager.xcframework/ios-arm64_x86_64-maccatalyst/TSLocationManager.framework/TSLocationManager +0 -0
  37. package/package.json +2 -2
  38. package/src/NativeModule.js +77 -31
  39. package/src/index.js +16 -16
  40. package/android/libs/com/transistorsoft/tslocationmanager/3.1.28/tslocationmanager-3.1.28.aar.md5 +0 -1
  41. package/android/libs/com/transistorsoft/tslocationmanager/3.1.28/tslocationmanager-3.1.28.aar.sha1 +0 -1
  42. package/android/libs/com/transistorsoft/tslocationmanager/3.1.28/tslocationmanager-3.1.28.aar.sha256 +0 -1
  43. package/android/libs/com/transistorsoft/tslocationmanager/3.1.28/tslocationmanager-3.1.28.aar.sha512 +0 -1
  44. package/android/libs/com/transistorsoft/tslocationmanager/3.1.28/tslocationmanager-3.1.28.pom.md5 +0 -1
  45. package/android/libs/com/transistorsoft/tslocationmanager/3.1.28/tslocationmanager-3.1.28.pom.sha1 +0 -1
  46. package/android/libs/com/transistorsoft/tslocationmanager/3.1.28/tslocationmanager-3.1.28.pom.sha256 +0 -1
  47. package/android/libs/com/transistorsoft/tslocationmanager/3.1.28/tslocationmanager-3.1.28.pom.sha512 +0 -1
  48. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.28/tslocationmanager-reverse-3.1.28.aar.md5 +0 -1
  49. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.28/tslocationmanager-reverse-3.1.28.aar.sha1 +0 -1
  50. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.28/tslocationmanager-reverse-3.1.28.aar.sha256 +0 -1
  51. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.28/tslocationmanager-reverse-3.1.28.aar.sha512 +0 -1
  52. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.28/tslocationmanager-reverse-3.1.28.pom.md5 +0 -1
  53. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.28/tslocationmanager-reverse-3.1.28.pom.sha1 +0 -1
  54. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.28/tslocationmanager-reverse-3.1.28.pom.sha256 +0 -1
  55. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.28/tslocationmanager-reverse-3.1.28.pom.sha512 +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.4.0 — 2021-10-25
4
+ * [Added] New `Authorization.strategy "SAS"` (alternative to default `JWT`).
5
+ * [Fixed] Fixed __`RCTEventEmitter`__ warning "addListener", "removeListeners". A corresponding fix has also been released for [react-native-background-fetch](https://github.com/transistorsoft/react-native-background-fetch/blob/master/CHANGELOG.md#404--2021-10-22) so be sure to update to `background-fetch >= 4.0.4`.
6
+ * [Changed] **Deprecated** `BackgroundGeolocation.removeListener`. All event-handlers now return a `react-native` `Subscription` instance containing a `.remove()` method. You will keep track of your own `subscription` instances and call `.remove()` upon them when you wish to remove an event listener. Eg:
7
+
8
+ ```javascript
9
+ /// OLD
10
+ const onLocation = (location) => {
11
+ console.log('[onLocation');
12
+ }
13
+ BackgroundGeolocation.onLocation(onLocation);
14
+ ...
15
+ // deprecated: removeListener
16
+ BackgroundGeolocation.removeListener('location', onLocation);
17
+
18
+ /// NEW: capture returned subscription instance.
19
+ const onLocationSubscription = BackgroundGeolocation.onLocation(onLocation);
20
+ ...
21
+ // Removing an event-listener.
22
+ onLocationSubscription.remove();
23
+ ```
24
+
25
+ ## 4.3.0 — 2021-09-14
26
+
27
+ * [Added][Android] Implement new Android 12 "reduced accuracy" mechanism `requestTemporaryFullAccuracy`.
28
+ * [Fixed][iOS] `Authorization.refreshPayload refreshToken` was not performing a String replace on the `{refreshToken}` template, instead over-writing the entire string. Eg: if provided with `'refresh_token': 'Bearer {refreshToken}`, `Bearer ` would be over-written and replaced with only the refresh-token.
29
+ * [Fixed][Android] Fixed crash reported by Huawei device, where verticalAccuracy returns NaN.
30
+
31
+ ## [4.2.2] — 2021-08-23
32
+ * [Fixed][iOS] add config change listeners for `heartbeatInterval` and `preventSuspend` to dynamically update interval when changed with `setConfig`.
33
+ * [Fixed][Android] Add `accuracyAuthorization` param to event data provided to `onProviderChange` event.
34
+ * [Changed][Android] Update Android default `okhttp` version to `3.12.13`.
35
+ * [Changed][Android] Update Android `eventbus` version to `3.2.0`.
36
+ * [Changed][Android] Update Android `android-permissions` to import from *MavenCentral* instead of deprecated `jCenter`.
37
+ * [Fixed][Android] Fix an edge-case requesting motion permission. If `getCurrentPosition()` is executed before `.start()`, the Android SDK fails to request motion permission.
38
+
39
+ ## 4.1.2 — 2021-07-05
40
+ * [Changed] Build iOS TSLocationManager.xcframework with XCode 12.4 instead of 12.5
41
+
42
+ ## 4.1.1 — 2021-06-11
43
+ * [Fixed][iOS] Reports 2 reports of iOS crash `NSInvalidArgumentException (TSLocation.m line 178)` with iOS 14
44
+ .x. Wrap JSON serialization in @try/@catch block. iOS JSON serialization docs state the supplied NSError err
45
+ or ref should report problems but it seems this is only "sometimes" now.
46
+
3
47
  ## 4.1.0 — 2021-06-07
4
48
  * [Changed] `Config.authorization` will perform regexp on the received response, searching for keys such as `accessToken`, `access_token`, `refreshToken`, `refresh_token`.
5
49
  * [Fixed] Typescript definition for interface `HeadlessEvent` was missing `timeout: boolean` attribute. Thanks @mikehardy.
@@ -3,13 +3,13 @@ apply plugin: 'com.android.library'
3
3
  // Android dependencies
4
4
  def DEFAULT_COMPILE_SDK_VERSION = 28
5
5
  def DEFAULT_TARGET_SDK_VERSION = 28
6
- def DEFAULT_APP_COMPAT_VERSION = "28.0.0"
6
+ def DEFAULT_APP_COMPAT_VERSION = "1.3.1"
7
7
 
8
8
  // Plugin dependencies
9
- def DEFAULT_GOOGLE_PLAY_SERVICES_LOCATION_VERSION = "17.0.0"
10
- def DEFAULT_OK_HTTP_VERSION = "3.12.1"
9
+ def DEFAULT_GOOGLE_PLAY_SERVICES_LOCATION_VERSION = "18.0.0"
10
+ def DEFAULT_OK_HTTP_VERSION = "3.12.13"
11
11
  def DEFAULT_ANDROID_PERMISSIONS_VERSION = "0.1.8"
12
- def DEFAULT_EVENTBUS_VERSION = "3.0.0"
12
+ def DEFAULT_EVENTBUS_VERSION = "3.2.0"
13
13
  def DEFAULT_LOCAL_BROADCAST_MANAGER_VERSION = "1.0.0"
14
14
 
15
15
  def useAndroidX = (project.hasProperty("android.useAndroidX")) ? project.property("android.useAndroidX") : false
@@ -37,10 +37,7 @@ repositories{
37
37
 
38
38
  dependencies {
39
39
  // Prefer appCompatVersion vs supportLibVersion.
40
- def appCompatVersion = safeExtGet('appCompatVersion', safeExtGet('supportLibVersion', DEFAULT_APP_COMPAT_VERSION))
41
-
42
- def appCompatMajorVersion = appCompatVersion.split('\\.')[0] as int
43
- def appCompatLibName = (appCompatMajorVersion < 20) ? "androidx.appcompat:appcompat" : "com.android.support:appcompat-v7"
40
+ def appCompatVersion = safeExtGet('appCompatVersion', DEFAULT_APP_COMPAT_VERSION)
44
41
  def playServicesLocationVersion = safeExtGet('googlePlayServicesLocationVersion', DEFAULT_GOOGLE_PLAY_SERVICES_LOCATION_VERSION)
45
42
  def okHttpVersion = safeExtGet('okHttpVersion', DEFAULT_OK_HTTP_VERSION)
46
43
  def androidPermissionsVersion = safeExtGet('androidPermissionsVersion', DEFAULT_ANDROID_PERMISSIONS_VERSION)
@@ -55,11 +52,11 @@ dependencies {
55
52
  api(group: 'com.transistorsoft', name:'tslocationmanager-reverse', version: '+')
56
53
  }
57
54
 
58
- implementation "$appCompatLibName:$appCompatVersion"
55
+ implementation "androidx.appcompat:appcompat:$appCompatVersion"
59
56
  implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
60
57
  implementation "org.greenrobot:eventbus:$eventBusVersion"
61
58
  implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
62
59
  implementation 'org.slf4j:slf4j-api:1.7.25'
63
60
  implementation 'com.github.tony19:logback-android:2.0.0'
64
- implementation "com.intentfilter:android-permissions:$androidPermissionsVersion"
61
+ implementation "io.github.nishkarsh:android-permissions:$androidPermissionsVersion"
65
62
  }
@@ -0,0 +1 @@
1
+ 738f4f927fde78332eeeb300ca1ac2ffbe6ddc26
@@ -0,0 +1 @@
1
+ a3dd1567edc75edbf1feb8bc3682d5e02ded8605e49854ba3169f391bfc8d09f
@@ -0,0 +1 @@
1
+ 8d405b0427fd37b225dd4ca90633614371c994f4e1fa2ada7c453a067c08ebc9f7b41b1ebfe13f09bafacfa948385b3a27b6964e3936ecb4e822c184603afe58
@@ -4,6 +4,6 @@
4
4
  <modelVersion>4.0.0</modelVersion>
5
5
  <groupId>com.transistorsoft</groupId>
6
6
  <artifactId>tslocationmanager</artifactId>
7
- <version>3.1.28</version>
7
+ <version>3.1.34</version>
8
8
  <packaging>aar</packaging>
9
9
  </project>
@@ -0,0 +1 @@
1
+ 008bd7362c4446af36bef9e156b6c702a7e3b781
@@ -0,0 +1 @@
1
+ 5dc8c142d50c9e6c9986a1b3d374e9ed86427da743e4030d24c45c9c0c4c2fdf
@@ -0,0 +1 @@
1
+ d8d251199fbd1fa61abcb4bf82b4e67624d82fc03fb34d114b10d99bcf4e5d443f65e38e16620a0020c566d844a51e600f4f5aa073c754a4ac2824210ba30498
@@ -3,19 +3,13 @@
3
3
  <groupId>com.transistorsoft</groupId>
4
4
  <artifactId>tslocationmanager</artifactId>
5
5
  <versioning>
6
- <latest>3.1.28</latest>
7
- <release>3.1.28</release>
6
+ <latest>3.1.34</latest>
7
+ <release>3.1.34</release>
8
8
  <versions>
9
- <version>3.1.20</version>
10
- <version>3.1.21</version>
11
- <version>3.1.22</version>
12
- <version>3.1.23</version>
13
- <version>3.1.24</version>
14
- <version>3.1.25</version>
15
- <version>3.1.26</version>
16
- <version>3.1.27</version>
17
- <version>3.1.28</version>
9
+ <version>3.1.32</version>
10
+ <version>3.1.33</version>
11
+ <version>3.1.34</version>
18
12
  </versions>
19
- <lastUpdated>20210607163803</lastUpdated>
13
+ <lastUpdated>20211013180057</lastUpdated>
20
14
  </versioning>
21
15
  </metadata>
@@ -0,0 +1 @@
1
+ 649f4c006732c5b2a04b6f90fba952377fa7281dda7374a20f5c67661439b45f
@@ -0,0 +1 @@
1
+ cfa5f14f859d2bd881867cc63b1968a7527b5a7e8082b551d3e3ad854783fcadefd9f2e21f2071201e1570347348cf4355e5d74c2049a1af4f21c1cca8c208f7
@@ -4,6 +4,6 @@
4
4
  <modelVersion>4.0.0</modelVersion>
5
5
  <groupId>com.transistorsoft</groupId>
6
6
  <artifactId>tslocationmanager-reverse</artifactId>
7
- <version>3.1.28</version>
7
+ <version>3.1.34</version>
8
8
  <packaging>aar</packaging>
9
9
  </project>
@@ -0,0 +1 @@
1
+ e6ebe3816a4c6ddb141b433b631e4e00c67adec24e46e45d0f06279cc0677e4f
@@ -0,0 +1 @@
1
+ f4c9c0482e0b822dcca71dcc32eaa5ee3a0caa93e0936e13e1ae38fb53f0b3137125b7cd90ff0469e53bb88caf961955972dc86a442dc2d937ae826a156df7f1
@@ -3,18 +3,13 @@
3
3
  <groupId>com.transistorsoft</groupId>
4
4
  <artifactId>tslocationmanager-reverse</artifactId>
5
5
  <versioning>
6
- <latest>3.1.28</latest>
7
- <release>3.1.28</release>
6
+ <latest>3.1.34</latest>
7
+ <release>3.1.34</release>
8
8
  <versions>
9
- <version>3.1.21</version>
10
- <version>3.1.22</version>
11
- <version>3.1.23</version>
12
- <version>3.1.24</version>
13
- <version>3.1.25</version>
14
- <version>3.1.26</version>
15
- <version>3.1.27</version>
16
- <version>3.1.28</version>
9
+ <version>3.1.32</version>
10
+ <version>3.1.33</version>
11
+ <version>3.1.34</version>
17
12
  </versions>
18
- <lastUpdated>20210607163803</lastUpdated>
13
+ <lastUpdated>20211013180057</lastUpdated>
19
14
  </versioning>
20
15
  </metadata>
@@ -115,6 +115,22 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
115
115
  mEvents.add(TSAuthorization.NAME);
116
116
 
117
117
  reactContext.addLifecycleEventListener(this);
118
+
119
+ BackgroundGeolocation adapter = getAdapter();
120
+ adapter.onLocation(new LocationCallback());
121
+ adapter.onMotionChange(new MotionChangeCallback());
122
+ adapter.onActivityChange(new ActivityChangeCallback());
123
+ adapter.onLocationProviderChange(new LocationProviderChangeCallback());
124
+ adapter.onGeofencesChange(new GeofencesChangeCallback());
125
+ adapter.onGeofence(new GeofenceCallback());
126
+ adapter.onHeartbeat(new HeartbeatCallback());
127
+ adapter.onHttp(new HttpResponseCallback());
128
+ adapter.onSchedule(new ScheduleCallback());
129
+ adapter.onPowerSaveChange(new PowerSaveChangeCallack());
130
+ adapter.onConnectivityChange(new ConnectivityChangeCallback());
131
+ adapter.onEnabledChange(new EnabledChangeCallback());
132
+ adapter.onNotificationAction(new NotificationActionCallback());
133
+ HttpService.getInstance(getReactApplicationContext()).onAuthorization(new AuthorizationCallback());
118
134
  }
119
135
 
120
136
  @Override
@@ -184,6 +200,7 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
184
200
  params.putBoolean("network", event.isNetworkEnabled());
185
201
  params.putBoolean("gps", event.isGPSEnabled());
186
202
  params.putBoolean("enabled", event.isEnabled());
203
+ params.putInt("accuracyAuthorization", event.getAccuracyAuthorization());
187
204
  params.putInt("status", event.getStatus());
188
205
  sendEvent(BackgroundGeolocation.EVENT_PROVIDERCHANGE, params);
189
206
  }
@@ -305,6 +322,7 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
305
322
  }
306
323
  }
307
324
  }
325
+
308
326
  @Override
309
327
  public void onHostResume() {
310
328
  if (!mInitialized) {
@@ -345,19 +363,24 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
345
363
  public void ready(ReadableMap params, final Callback success, final Callback failure) {
346
364
  TSConfig config = TSConfig.getInstance(getReactApplicationContext());
347
365
 
366
+ boolean reset = true;
367
+ if (params.hasKey("reset")) {
368
+ reset = params.getBoolean("reset");
369
+ }
370
+
348
371
  if (mReady) {
349
- TSLog.logger.warn(TSLog.warn("#ready already called. Redirecting to #setConfig"));
350
- setConfig(params, success, failure);
372
+ if (reset) {
373
+ TSLog.logger.warn(TSLog.warn("#ready already called. Redirecting to #setConfig"));
374
+ setConfig(params, success, failure);
375
+ } else {
376
+ TSLog.logger.warn(TSLog.warn("#ready already called. Ignored config since reset: false"));
377
+ }
351
378
  return;
352
379
  }
353
380
  mReady = true;
354
381
  if (config.isFirstBoot()) {
355
382
  config.updateWithJSONObject(mapToJson(setHeadlessJobService(params)));
356
383
  } else {
357
- boolean reset = true;
358
- if (params.hasKey("reset")) {
359
- reset = params.getBoolean("reset");
360
- }
361
384
  if (reset) {
362
385
  config.reset();
363
386
  config.updateWithJSONObject(mapToJson(setHeadlessJobService(params)));
@@ -972,92 +995,31 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
972
995
  success.invoke(status);
973
996
  }
974
997
  @Override public void onFailure(int status) {
975
- error.invoke(status);
998
+ success.invoke(status);
976
999
  }
977
1000
  });
978
1001
  }
979
1002
 
980
1003
  @ReactMethod
981
- public void requestTemporaryFullAccuracy(String purpose, Callback success, Callback failure) {
982
- // Note: No Android implementation -- this is an iOS-only mechanism currently.
983
- // return iOS CLAccuracyAuthorizationFull (0)
984
- success.invoke(LocationProviderChangeEvent.ACCURACY_AUTHORIZATION_FULL);
985
- }
986
-
987
- @ReactMethod
988
- public void addEventListener(String event) {
989
-
990
- if (!mEvents.contains(event)) {
991
- TSLog.logger.warn(TSLog.warn("[RNBackgroundGeolocation addListener] Unknown event: " + event));
992
- return;
993
- }
994
- BackgroundGeolocation adapter = getAdapter();
995
- Integer count;
996
-
997
- synchronized(mListeners) {
998
- if (mListeners.containsKey(event)) {
999
- count = mListeners.get(event);
1000
- count++;
1001
- mListeners.put(event, count);
1002
- } else {
1003
- count = 1;
1004
- mListeners.put(event, count);
1004
+ public void requestTemporaryFullAccuracy(String purpose, final Callback success, final Callback failure) {
1005
+ getAdapter().requestTemporaryFullAccuracy(purpose, new TSRequestPermissionCallback() {
1006
+ @Override public void onSuccess(int accuracyAuthorization) {
1007
+ success.invoke(accuracyAuthorization);
1005
1008
  }
1006
- }
1007
- if (count == 1) {
1008
- if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_LOCATION)) {
1009
- adapter.onLocation(new LocationCallback());
1010
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_MOTIONCHANGE)) {
1011
- adapter.onMotionChange(new MotionChangeCallback());
1012
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_ACTIVITYCHANGE)) {
1013
- adapter.onActivityChange(new ActivityChangeCallback());
1014
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_PROVIDERCHANGE)) {
1015
- adapter.onLocationProviderChange(new LocationProviderChangeCallback());
1016
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_GEOFENCESCHANGE)) {
1017
- adapter.onGeofencesChange(new GeofencesChangeCallback());
1018
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_GEOFENCE)) {
1019
- adapter.onGeofence(new GeofenceCallback());
1020
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_HEARTBEAT)) {
1021
- adapter.onHeartbeat(new HeartbeatCallback());
1022
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_HTTP)) {
1023
- adapter.onHttp(new HttpResponseCallback());
1024
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_SCHEDULE)) {
1025
- adapter.onSchedule(new ScheduleCallback());
1026
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_POWERSAVECHANGE)) {
1027
- adapter.onPowerSaveChange(new PowerSaveChangeCallack());
1028
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_CONNECTIVITYCHANGE)) {
1029
- adapter.onConnectivityChange(new ConnectivityChangeCallback());
1030
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_ENABLEDCHANGE)) {
1031
- adapter.onEnabledChange(new EnabledChangeCallback());
1032
- } else if (event.equalsIgnoreCase(BackgroundGeolocation.EVENT_NOTIFICATIONACTION)) {
1033
- adapter.onNotificationAction(new NotificationActionCallback());
1034
- } else if (event.equalsIgnoreCase(TSAuthorization.NAME)) {
1035
- HttpService.getInstance(getReactApplicationContext()).onAuthorization(new AuthorizationCallback());
1009
+ @Override public void onFailure(int accuracyAuthorization) {
1010
+ success.invoke(accuracyAuthorization);
1036
1011
  }
1037
- }
1012
+ });
1038
1013
  }
1039
1014
 
1040
1015
  @ReactMethod
1041
- public void removeListener(String event) {
1042
- Integer count;
1043
-
1044
- synchronized (mListeners) {
1045
- if (mListeners.containsKey(event)) {
1046
- count = mListeners.get(event);
1047
- count--;
1048
- if (count > 0) {
1049
- mListeners.put(event, count);
1050
- } else {
1051
- getAdapter().removeListeners(event);
1052
- }
1053
- }
1054
- }
1016
+ public void addListener(String event) {
1017
+ // Keep: Required for RN built-in NativeEventEmitter calls.
1055
1018
  }
1056
1019
 
1057
1020
  @ReactMethod
1058
- public void removeAllListeners(Callback success, Callback failure) {
1059
- removeAllListeners();
1060
- success.invoke();
1021
+ public void removeListeners(Integer count) {
1022
+ // Keep: Required for RN built-in NativeEventEmitter calls.
1061
1023
  }
1062
1024
 
1063
1025
  private void removeAllListeners() {
@@ -30,22 +30,7 @@ static NSString *const EVENT_NOTIFICATIONACTION = @"notificationaction";
30
30
  static NSString *const EVENT_AUTHORIZATION = @"authorization";
31
31
 
32
32
  @implementation RNBackgroundGeolocation {
33
- NSMutableDictionary *listeners;
34
33
  BOOL ready;
35
- void(^onLocation)(TSLocation*);
36
- void(^onLocationError)(NSError*);
37
- void(^onMotionChange)(TSLocation*);
38
- void(^onActivityChange)(TSActivityChangeEvent*);
39
- void(^onHeartbeat)(TSHeartbeatEvent*);
40
- void(^onGeofence)(TSGeofenceEvent*);
41
- void(^onGeofencesChange)(TSGeofencesChangeEvent*);
42
- void(^onHttp)(TSHttpEvent*);
43
- void(^onProviderChange)(TSProviderChangeEvent*);
44
- void(^onSchedule)(TSScheduleEvent*);
45
- void(^onPowerSaveChange)(TSPowerSaveChangeEvent*);
46
- void(^onConnectivityChange)(TSConnectivityChangeEvent*);
47
- void(^onEnabledChange)(TSEnabledChangeEvent*);
48
- void(^onAuthorization)(TSAuthorizationEvent*);
49
34
  }
50
35
 
51
36
  @synthesize locationManager;
@@ -66,60 +51,7 @@ RCT_EXPORT_MODULE();
66
51
  if (self) {
67
52
  ready = NO;
68
53
 
69
- __typeof(self) __weak me = self;
70
-
71
54
  // Build event-listener blocks
72
- onLocation = ^void(TSLocation *location) {
73
- [me sendEvent:EVENT_LOCATION body:[location toDictionary]];
74
- };
75
- onLocationError = ^void(NSError *error) {
76
- [me sendEvent:EVENT_LOCATION body: @{@"error":@(error.code)}];
77
- };
78
- onMotionChange = ^void(TSLocation *location) {
79
- [me sendEvent:EVENT_MOTIONCHANGE body:@{@"isMoving":@(location.isMoving), @"location":[location toDictionary]}];
80
- };
81
- onActivityChange = ^void(TSActivityChangeEvent *event) {
82
- NSDictionary *params = @{@"activity": event.activity, @"confidence": @(event.confidence)};
83
- [me sendEvent:EVENT_ACTIVITYCHANGE body:params];
84
- };
85
- onHeartbeat = ^void(TSHeartbeatEvent *event) {
86
- [me sendEvent:EVENT_HEARTBEAT body:@{@"location":[event.location toDictionary]}];
87
- };
88
- onGeofence = ^void(TSGeofenceEvent *event) {
89
- NSMutableDictionary *params = [[event toDictionary] mutableCopy];
90
- [params setObject:[event.location toDictionary] forKey:@"location"];
91
- [me sendEvent:EVENT_GEOFENCE body:params];
92
- };
93
- onGeofencesChange = ^void(TSGeofencesChangeEvent *event) {
94
- [me sendEvent:EVENT_GEOFENCESCHANGE body:[event toDictionary]];
95
- };
96
- onHttp = ^void(TSHttpEvent *response) {
97
- NSDictionary *params = @{@"success": @(response.isSuccess), @"status": @(response.statusCode), @"responseText":response.responseText};
98
- [me sendEvent:EVENT_HTTP body:params];
99
- };
100
- onProviderChange = ^void(TSProviderChangeEvent *event) {
101
- [me sendEvent:EVENT_PROVIDERCHANGE body:[event toDictionary]];
102
- };
103
- onSchedule = ^void(TSScheduleEvent *event) {
104
- [me sendEvent:EVENT_SCHEDULE body:event.state];
105
- };
106
- onPowerSaveChange = ^void(TSPowerSaveChangeEvent *event) {
107
- [me sendEvent:EVENT_POWERSAVECHANGE body:@(event.isPowerSaveMode)];
108
- };
109
- onConnectivityChange = ^void(TSConnectivityChangeEvent *event) {
110
- NSDictionary *params = @{@"connected":@(event.hasConnection)};
111
- [me sendEvent:EVENT_CONNECTIVITYCHANGE body:params];
112
- };
113
- onEnabledChange = ^void(TSEnabledChangeEvent *event) {
114
- [me sendEvent:EVENT_ENABLEDCHANGE body:@(event.enabled)];
115
- };
116
- onAuthorization = ^void(TSAuthorizationEvent *event) {
117
- [me sendEvent:EVENT_AUTHORIZATION body:[event toDictionary]];
118
- };
119
-
120
- // EventEmitter listener-counts
121
- listeners = [NSMutableDictionary new];
122
-
123
55
  // TSLocationManager instance
124
56
  locationManager = [TSLocationManager sharedInstance];
125
57
 
@@ -127,10 +59,59 @@ RCT_EXPORT_MODULE();
127
59
  UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
128
60
  locationManager.viewController = root;
129
61
  }
130
-
131
62
  return self;
132
63
  }
133
64
 
65
+ -(void) registerEventListeners {
66
+ __typeof(self) __weak me = self;
67
+ [locationManager onLocation:^(TSLocation *location) {
68
+ [me sendEvent:EVENT_LOCATION body:[location toDictionary]];
69
+ } failure:^(NSError *error) {
70
+ [me sendEvent:EVENT_LOCATION body: @{@"error":@(error.code)}];
71
+ }];
72
+ [locationManager onMotionChange:^(TSLocation *location) {
73
+ [me sendEvent:EVENT_MOTIONCHANGE body:@{@"isMoving":@(location.isMoving), @"location":[location toDictionary]}];
74
+ }];
75
+ [locationManager onActivityChange:^(TSActivityChangeEvent *event) {
76
+ NSDictionary *params = @{@"activity": event.activity, @"confidence": @(event.confidence)};
77
+ [me sendEvent:EVENT_ACTIVITYCHANGE body:params];
78
+ }];
79
+ [locationManager onHeartbeat:^(TSHeartbeatEvent *event) {
80
+ [me sendEvent:EVENT_HEARTBEAT body:@{@"location":[event.location toDictionary]}];
81
+ }];
82
+ [locationManager onGeofence:^(TSGeofenceEvent *event) {
83
+ NSMutableDictionary *params = [[event toDictionary] mutableCopy];
84
+ [params setObject:[event.location toDictionary] forKey:@"location"];
85
+ [me sendEvent:EVENT_GEOFENCE body:params];
86
+ }];
87
+ [locationManager onGeofencesChange:^(TSGeofencesChangeEvent *event) {
88
+ [me sendEvent:EVENT_GEOFENCESCHANGE body:[event toDictionary]];
89
+ }];
90
+ [locationManager onHttp:^(TSHttpEvent *response) {
91
+ NSDictionary *params = @{@"success": @(response.isSuccess), @"status": @(response.statusCode), @"responseText":response.responseText};
92
+ [me sendEvent:EVENT_HTTP body:params];
93
+ }];
94
+ [locationManager onProviderChange:^(TSProviderChangeEvent *event) {
95
+ [me sendEvent:EVENT_PROVIDERCHANGE body:[event toDictionary]];
96
+ }];
97
+ [locationManager onSchedule:^(TSScheduleEvent *event) {
98
+ [me sendEvent:EVENT_SCHEDULE body:event.state];
99
+ }];
100
+ [locationManager onPowerSaveChange:^(TSPowerSaveChangeEvent *event) {
101
+ [me sendEvent:EVENT_POWERSAVECHANGE body:@(event.isPowerSaveMode)];
102
+ }];
103
+ [locationManager onConnectivityChange:^(TSConnectivityChangeEvent *event) {
104
+ NSDictionary *params = @{@"connected":@(event.hasConnection)};
105
+ [me sendEvent:EVENT_CONNECTIVITYCHANGE body:params];
106
+ }];
107
+ [locationManager onEnabledChange:^(TSEnabledChangeEvent *event) {
108
+ [me sendEvent:EVENT_ENABLEDCHANGE body:@(event.enabled)];
109
+ }];
110
+ [locationManager onAuthorization:^(TSAuthorizationEvent *event) {
111
+ [me sendEvent:EVENT_AUTHORIZATION body:[event toDictionary]];
112
+ }];
113
+ }
114
+
134
115
  - (NSArray<NSString *> *)supportedEvents {
135
116
  return @[
136
117
  EVENT_LOCATION,
@@ -174,20 +155,26 @@ RCT_EXPORT_METHOD(reset:(NSDictionary*)params success:(RCTResponseSenderBlock)su
174
155
  */
175
156
  RCT_EXPORT_METHOD(ready:(NSDictionary*)params success:(RCTResponseSenderBlock)success failure:(RCTResponseSenderBlock)failure)
176
157
  {
158
+ BOOL reset = (params[@"reset"]) ? [params[@"reset"] boolValue] : YES;
177
159
  if (ready) {
178
- [locationManager log:@"warn" message:@"#ready already called. Redirecting to #setConfig"];
179
160
  TSConfig *config = [TSConfig sharedInstance];
180
- [config updateWithDictionary:params];
161
+ if (reset) {
162
+ [locationManager log:@"warn" message:@"#ready already called. Redirecting to #setConfig"];
163
+ [config updateWithDictionary:params];
164
+ } else {
165
+ [locationManager log:@"warn" message:@"#ready already called. Ignored Config since reset: false"];
166
+ }
181
167
  success(@[[config toDictionary]]);
182
168
  return;
183
169
  }
184
170
  ready = YES;
171
+ [self registerEventListeners];
172
+
185
173
  dispatch_async(dispatch_get_main_queue(), ^{
186
174
  TSConfig *config = [TSConfig sharedInstance];
187
175
  if (config.isFirstBoot) {
188
176
  [config updateWithDictionary:params];
189
177
  } else {
190
- BOOL reset = (params[@"reset"]) ? [params[@"reset"] boolValue] : YES;
191
178
  if (reset) {
192
179
  [config reset:YES];
193
180
  [config updateWithDictionary:params];
@@ -215,72 +202,10 @@ RCT_EXPORT_METHOD(configure:(NSDictionary*)params success:(RCTResponseSenderBloc
215
202
  });
216
203
  }
217
204
 
218
- RCT_EXPORT_METHOD(addEventListener:(NSString*)event)
219
- {
220
- @synchronized(listeners) {
221
- if ([listeners objectForKey:event]) {
222
- // Increment listener-count for this event
223
- NSInteger count = [[listeners objectForKey:event] integerValue];
224
- count++;
225
- [listeners setObject:@(count) forKey:event];
226
- } else {
227
- // First listener for this event
228
- [listeners setObject:@(1) forKey:event];
229
-
230
- if ([event isEqualToString:EVENT_LOCATION]) {
231
- [locationManager onLocation:onLocation failure:onLocationError];
232
- } else if ([event isEqualToString:EVENT_MOTIONCHANGE]) {
233
- [locationManager onMotionChange:onMotionChange];
234
- } else if ([event isEqualToString:EVENT_ACTIVITYCHANGE]) {
235
- [locationManager onActivityChange:onActivityChange];
236
- } else if ([event isEqualToString:EVENT_HEARTBEAT]) {
237
- [locationManager onHeartbeat:onHeartbeat];
238
- } else if ([event isEqualToString:EVENT_GEOFENCE]) {
239
- [locationManager onGeofence:onGeofence];
240
- } else if ([event isEqualToString:EVENT_GEOFENCESCHANGE]) {
241
- [locationManager onGeofencesChange:onGeofencesChange];
242
- } else if ([event isEqualToString:EVENT_HTTP]) {
243
- [locationManager onHttp:onHttp];
244
- } else if ([event isEqualToString:EVENT_PROVIDERCHANGE]) {
245
- [locationManager onProviderChange:onProviderChange];
246
- } else if ([event isEqualToString:EVENT_SCHEDULE]) {
247
- [locationManager onSchedule:onSchedule];
248
- } else if ([event isEqualToString:EVENT_POWERSAVECHANGE]) {
249
- [locationManager onPowerSaveChange:onPowerSaveChange];
250
- } else if ([event isEqualToString:EVENT_CONNECTIVITYCHANGE]) {
251
- [locationManager onConnectivityChange:onConnectivityChange];
252
- } else if ([event isEqualToString:EVENT_ENABLEDCHANGE]) {
253
- [locationManager onEnabledChange:onEnabledChange];
254
- } else if ([event isEqualToString:EVENT_AUTHORIZATION]) {
255
- [[TSHttpService sharedInstance] onAuthorization:onAuthorization];
256
- } else if ([event isEqualToString:EVENT_NOTIFICATIONACTION]) {
257
- // No iOS implementation.
258
- }
259
- }
260
- }
261
- }
262
205
 
263
- RCT_EXPORT_METHOD(removeListener:(NSString*)event)
264
- {
265
- @synchronized(listeners) {
266
- if ([listeners objectForKey:event]) {
267
- // Decrement listener-count for this event.
268
- NSInteger count = [[listeners objectForKey:event] integerValue];
269
- count--;
270
- if (count > 0) {
271
- [listeners setObject:@(count) forKey:event];
272
- } else {
273
- // No more listeners: tell TSLocationManager to removeListeners for this event.
274
- [locationManager removeListeners];
275
- [listeners removeObjectForKey:event];
276
- }
277
- }
278
- }
279
- }
280
206
 
281
207
  RCT_EXPORT_METHOD(removeAllListeners:(RCTResponseSenderBlock)success failure:(RCTResponseSenderBlock)failure)
282
208
  {
283
- @synchronized(listeners) { [listeners removeAllObjects]; }
284
209
  [locationManager removeListeners];
285
210
  success(@[]);
286
211
  }
@@ -736,7 +661,7 @@ RCT_EXPORT_METHOD(playSound:(int)soundId)
736
661
 
737
662
  - (void)invalidate
738
663
  {
739
- @synchronized(listeners) { [listeners removeAllObjects]; }
664
+ [super invalidate];
740
665
  [locationManager removeListeners];
741
666
  dispatch_async(dispatch_get_main_queue(), ^{
742
667
  [self.locationManager stopWatchPosition];
@@ -745,7 +670,6 @@ RCT_EXPORT_METHOD(playSound:(int)soundId)
745
670
 
746
671
  - (void)dealloc
747
672
  {
748
- @synchronized(listeners) { [listeners removeAllObjects]; }
749
673
  [locationManager removeListeners];
750
674
  locationManager = nil;
751
675
  }
@@ -6,47 +6,47 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_armv7</string>
9
+ <string>ios-arm64_i386_x86_64-simulator</string>
10
10
  <key>LibraryPath</key>
11
11
  <string>TSLocationManager.framework</string>
12
12
  <key>SupportedArchitectures</key>
13
13
  <array>
14
14
  <string>arm64</string>
15
- <string>armv7</string>
15
+ <string>i386</string>
16
+ <string>x86_64</string>
16
17
  </array>
17
18
  <key>SupportedPlatform</key>
18
19
  <string>ios</string>
20
+ <key>SupportedPlatformVariant</key>
21
+ <string>simulator</string>
19
22
  </dict>
20
23
  <dict>
21
24
  <key>LibraryIdentifier</key>
22
- <string>ios-arm64_x86_64-maccatalyst</string>
25
+ <string>ios-arm64_armv7</string>
23
26
  <key>LibraryPath</key>
24
27
  <string>TSLocationManager.framework</string>
25
28
  <key>SupportedArchitectures</key>
26
29
  <array>
27
30
  <string>arm64</string>
28
- <string>x86_64</string>
31
+ <string>armv7</string>
29
32
  </array>
30
33
  <key>SupportedPlatform</key>
31
34
  <string>ios</string>
32
- <key>SupportedPlatformVariant</key>
33
- <string>maccatalyst</string>
34
35
  </dict>
35
36
  <dict>
36
37
  <key>LibraryIdentifier</key>
37
- <string>ios-arm64_i386_x86_64-simulator</string>
38
+ <string>ios-arm64_x86_64-maccatalyst</string>
38
39
  <key>LibraryPath</key>
39
40
  <string>TSLocationManager.framework</string>
40
41
  <key>SupportedArchitectures</key>
41
42
  <array>
42
43
  <string>arm64</string>
43
- <string>i386</string>
44
44
  <string>x86_64</string>
45
45
  </array>
46
46
  <key>SupportedPlatform</key>
47
47
  <string>ios</string>
48
48
  <key>SupportedPlatformVariant</key>
49
- <string>simulator</string>
49
+ <string>maccatalyst</string>
50
50
  </dict>
51
51
  </array>
52
52
  <key>CFBundlePackageType</key>
@@ -138,7 +138,7 @@
138
138
  </data>
139
139
  <key>Info.plist</key>
140
140
  <data>
141
- 02nBBiQf2AIoZ8Fd9T0qx/gcFqs=
141
+ lCvkm6gOxhn5NxMHGiCuBZPRf6w=
142
142
  </data>
143
143
  <key>Modules/module.modulemap</key>
144
144
  <data>
@@ -3,7 +3,7 @@
3
3
  <plist version="1.0">
4
4
  <dict>
5
5
  <key>BuildMachineOSBuild</key>
6
- <string>20E241</string>
6
+ <string>20G165</string>
7
7
  <key>CFBundleDevelopmentRegion</key>
8
8
  <string>en</string>
9
9
  <key>CFBundleExecutable</key>
@@ -17,29 +17,29 @@
17
17
  <key>CFBundlePackageType</key>
18
18
  <string>FMWK</string>
19
19
  <key>CFBundleShortVersionString</key>
20
- <string>4.0.3</string>
20
+ <string>4.0.7</string>
21
21
  <key>CFBundleSupportedPlatforms</key>
22
22
  <array>
23
23
  <string>MacOSX</string>
24
24
  </array>
25
25
  <key>CFBundleVersion</key>
26
- <string>377</string>
26
+ <string>381</string>
27
27
  <key>DTCompiler</key>
28
28
  <string>com.apple.compilers.llvm.clang.1_0</string>
29
29
  <key>DTPlatformBuild</key>
30
- <string>12E262</string>
30
+ <string>12D4e</string>
31
31
  <key>DTPlatformName</key>
32
32
  <string>macosx</string>
33
33
  <key>DTPlatformVersion</key>
34
- <string>11.3</string>
34
+ <string>11.1</string>
35
35
  <key>DTSDKBuild</key>
36
- <string>20E214</string>
36
+ <string>20C63</string>
37
37
  <key>DTSDKName</key>
38
- <string>macosx11.3</string>
38
+ <string>macosx11.1</string>
39
39
  <key>DTXcode</key>
40
- <string>1250</string>
40
+ <string>1240</string>
41
41
  <key>DTXcodeBuild</key>
42
- <string>12E262</string>
42
+ <string>12D4e</string>
43
43
  <key>LSMinimumSystemVersion</key>
44
44
  <string>10.15</string>
45
45
  <key>UIDeviceFamily</key>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-background-geolocation",
3
- "version": "4.1.0",
3
+ "version": "4.4.0",
4
4
  "description": "The most sophisticated cross-platform background location-tracking & geofencing module with battery-conscious motion-detection intelligence",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -43,7 +43,7 @@
43
43
  "react-native": ">=0.36.0"
44
44
  },
45
45
  "dependencies": {
46
- "react-native-background-fetch": "~4.0.1"
46
+ "react-native-background-fetch": "~4.0.4"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@transistorsoft/typedoc-theme": "^2.0.7",
@@ -51,9 +51,51 @@ const LOGGER = {
51
51
  }
52
52
  }
53
53
 
54
+ /// Internal Subscription instance
55
+ /// @deprecated.
56
+ class Subscription {
57
+ constructor(event, subscription, callback) {
58
+ this.event = event;
59
+ this.subscription = subscription;
60
+ this.callback = callback;
61
+ }
62
+ }
63
+
54
64
  // Plugin event listener subscriptions
65
+ // @deprecated.
55
66
  let EVENT_SUBSCRIPTIONS = [];
56
67
 
68
+ const findEventSubscriptionByEvent = (event, callback) => {
69
+ let found = null;
70
+ for (let n=0,len=EVENT_SUBSCRIPTIONS.length;n<len;n++) {
71
+ let sub = EVENT_SUBSCRIPTIONS[n];
72
+ if ((sub.event === event) && (sub.callback === callback)) {
73
+ found = sub;
74
+ break;
75
+ }
76
+ }
77
+ return found;
78
+ }
79
+
80
+ const findEventSubscription = (subscription) => {
81
+ let found = null;
82
+ for (let n=0,len=EVENT_SUBSCRIPTIONS.length;n<len;n++) {
83
+ let sub = EVENT_SUBSCRIPTIONS[n];
84
+ if (sub.subscription === subscription) {
85
+ found = sub;
86
+ break;
87
+ }
88
+ }
89
+ return found;
90
+ }
91
+
92
+ const removeEventSubscription = (subscription) => {
93
+ const found = findEventSubscription(subscription);
94
+ if (found !== null) {
95
+ EVENT_SUBSCRIPTIONS.splice(EVENT_SUBSCRIPTIONS.indexOf(found), 1);
96
+ }
97
+ }
98
+
57
99
  // Validate provided config for #ready, #setConfig
58
100
  const validateConfig = (config) => {
59
101
  // Detect obsolete notification* fields and re-map to Notification instance.
@@ -83,13 +125,6 @@ const validateConfig = (config) => {
83
125
  return config;
84
126
  };
85
127
 
86
- class Subscription {
87
- constructor(subscription, callback) {
88
- this.subscription = subscription;
89
- this.callback = callback;
90
- }
91
- }
92
-
93
128
  // Cached copy of DeviceInfo.
94
129
  let deviceInfo = null;
95
130
  /**
@@ -161,7 +196,7 @@ export default class NativeModule {
161
196
  if (!Events[event.toUpperCase()]) {
162
197
  throw (TAG + "#addListener - Unknown event '" + event + "'");
163
198
  }
164
- let handler = (response) => {
199
+ const handler = (response) => {
165
200
  if (response.hasOwnProperty("error") && (response.error != null)) {
166
201
  if (typeof(failure) === 'function') {
167
202
  failure(response.error);
@@ -172,38 +207,49 @@ export default class NativeModule {
172
207
  success(response);
173
208
  }
174
209
  }
175
- let subscription = new Subscription(EventEmitter.addListener(event, handler), success);
176
- EVENT_SUBSCRIPTIONS.push(subscription);
177
- RNBackgroundGeolocation.addEventListener(event);
210
+ const subscription = EventEmitter.addListener(event, handler);
211
+
212
+ if (typeof(subscription.remove) === 'function') {
213
+ // React Native 0.65+ altered EventEmitter
214
+ //
215
+ // Wrap .remove() to remove from our own local EVENT_SUBSCRIPTIONS cache.
216
+ // Eventually we can remove this local cache entirely once people are trained
217
+ // to not use removeListener.
218
+ const originalRemove = subscription.remove;
219
+ subscription.remove = () => {
220
+ originalRemove.call(subscription);
221
+ removeEventSubscription(subscription);
222
+ }
223
+ } else {
224
+ // Old RN API? Create a .remove() method.
225
+ subscription.remove = () => {
226
+ EventEmitter.removeListener(event, handler);
227
+ removeEventSubscription(subscription);
228
+ }
229
+ }
230
+ EVENT_SUBSCRIPTIONS.push(new Subscription(event, subscription, success));
231
+ return subscription;
178
232
  }
179
233
 
234
+ // @deprecated in favor of subscription.remove().
180
235
  static removeListener(event, callback, success, failure) {
181
- let found = null;
182
- for (let n=0,len=EVENT_SUBSCRIPTIONS.length;n<len;n++) {
183
- let sub = EVENT_SUBSCRIPTIONS[n];
184
- if ((sub.subscription.eventType === event) && (sub.callback === callback)) {
185
- found = sub;
186
- break;
187
- }
188
- }
236
+ console.warn('BackgroundGeolocation.removeListener is deprecated. Event-listener methods (eg: onLocation) now return a subscription instance. Call subscription.remove() on the returned subscription instead. Eg:\nconst subscription = BackgroundGeolocation.onLocation(myLocationHandler)\n...\nsubscription.remove()');
237
+ const found = findEventSubscriptionByEvent(event, callback);
189
238
  if (found !== null) {
190
- EVENT_SUBSCRIPTIONS.splice(EVENT_SUBSCRIPTIONS.indexOf(found), 1);
191
- RNBackgroundGeolocation.removeListener(event);
192
- EventEmitter.removeListener(event, found.subscription.listener);
239
+ found.subscription.remove();
240
+ return true;
241
+ } else {
242
+ return false;
193
243
  }
194
244
  }
195
245
 
196
246
  static removeListeners() {
197
247
  return new Promise((resolve, reject) => {
198
- let success = async () => {
199
- for (const event in Events) {
200
- EventEmitter.removeAllListeners(Events[event.toUpperCase()]);
201
- }
202
- EVENT_SUBSCRIPTIONS = [];
203
- resolve();
204
- }
205
- let failure = (error) => { reject(error) }
206
- RNBackgroundGeolocation.removeAllListeners(success, failure);
248
+ EVENT_SUBSCRIPTIONS.forEach((sub) => {
249
+ sub.subscription.remove();
250
+ });
251
+ EVENT_SUBSCRIPTIONS = [];
252
+ resolve();
207
253
  });
208
254
  }
209
255
 
package/src/index.js CHANGED
@@ -197,67 +197,67 @@ export default class BackgroundGeolocation {
197
197
  if (typeof(event) != 'string') { throw "BackgroundGeolocation#on must be provided a {String} event as 1st argument." }
198
198
  if (Events[event]) { throw "BackgroundGeolocation#on - Unknown event '" + event + "'" }
199
199
  if (typeof(success) != 'function') { throw "BackgroundGeolocation#on must be provided a callback as 2nd argument. If you're attempting to use the Promise API to listen to an event, it won't work, since a Promise can only evaluate once, while the callback function must be executed for each event." }
200
- NativeModule.addListener.apply(NativeModule, arguments);
200
+ return NativeModule.addListener.apply(NativeModule, arguments);
201
201
  }
202
202
  // @alias #removeListener
203
203
  static on(event, success, failure) {
204
- this.addListener.apply(this, arguments);
204
+ return this.addListener.apply(this, arguments);
205
205
  }
206
206
 
207
207
  static onLocation(success, failure) {
208
- this.addListener(Events.LOCATION, success, failure);
208
+ return this.addListener(Events.LOCATION, success, failure);
209
209
  }
210
210
 
211
211
  static onMotionChange(callback) {
212
- this.addListener(Events.MOTIONCHANGE, callback);
212
+ return this.addListener(Events.MOTIONCHANGE, callback);
213
213
  }
214
214
 
215
215
  static onHttp(callback) {
216
- this.addListener(Events.HTTP, callback);
216
+ return this.addListener(Events.HTTP, callback);
217
217
  }
218
218
 
219
219
  static onHeartbeat(callback) {
220
- this.addListener(Events.HEARTBEAT, callback);
220
+ return this.addListener(Events.HEARTBEAT, callback);
221
221
  }
222
222
 
223
223
  static onProviderChange(callback) {
224
- this.addListener(Events.PROVIDERCHANGE, callback);
224
+ return this.addListener(Events.PROVIDERCHANGE, callback);
225
225
  }
226
226
 
227
227
  static onActivityChange(callback) {
228
- this.addListener(Events.ACTIVITYCHANGE, callback);
228
+ return this.addListener(Events.ACTIVITYCHANGE, callback);
229
229
  }
230
230
 
231
231
  static onGeofence(callback) {
232
- this.addListener(Events.GEOFENCE, callback);
232
+ return this.addListener(Events.GEOFENCE, callback);
233
233
  }
234
234
 
235
235
  static onGeofencesChange(callback) {
236
- this.addListener(Events.GEOFENCESCHANGE, callback);
236
+ return this.addListener(Events.GEOFENCESCHANGE, callback);
237
237
  }
238
238
 
239
239
  static onSchedule(callback) {
240
- this.addListener(Events.SCHEDULE, callback);
240
+ return this.addListener(Events.SCHEDULE, callback);
241
241
  }
242
242
 
243
243
  static onEnabledChange(callback) {
244
- this.addListener(Events.ENABLEDCHANGE, callback);
244
+ return this.addListener(Events.ENABLEDCHANGE, callback);
245
245
  }
246
246
 
247
247
  static onConnectivityChange(callback) {
248
- this.addListener(Events.CONNECTIVITYCHANGE, callback);
248
+ return this.addListener(Events.CONNECTIVITYCHANGE, callback);
249
249
  }
250
250
 
251
251
  static onPowerSaveChange(callback) {
252
- this.addListener(Events.POWERSAVECHANGE, callback);
252
+ return this.addListener(Events.POWERSAVECHANGE, callback);
253
253
  }
254
254
 
255
255
  static onNotificationAction(callback) {
256
- this.addListener(Events.NOTIFICATIONACTION, callback);
256
+ return this.addListener(Events.NOTIFICATIONACTION, callback);
257
257
  }
258
258
 
259
259
  static onAuthorization(callback) {
260
- this.addListener(Events.AUTHORIZATION, callback);
260
+ return this.addListener(Events.AUTHORIZATION, callback);
261
261
  }
262
262
 
263
263
  /**
@@ -1 +0,0 @@
1
- bda4d3129bb58765f7b9292943542e60357ce202
@@ -1 +0,0 @@
1
- 6464bafc954e658057b73b669694fe43fe1792a4ecb25b9428189c255888027b
@@ -1 +0,0 @@
1
- b7cc8172103cd78d5e65e1a4a851784d98d1d9b01f165835709370eb51aa92857bc446222b041e606f944182dfddb170bbcc16d46a10789f9210d2581b64e976
@@ -1 +0,0 @@
1
- 113f3684c91caa0cceafafe98d6df048273f05bd
@@ -1 +0,0 @@
1
- 9989e2650d9d34ad583683699263ca3bd159db72fbb1d481568a96bc5f277617
@@ -1 +0,0 @@
1
- b5d20d4cd3d800cd77b89cd274b37a408b5158adcdafff0f2c7b520fb1bc4e6087d656e5f86298e2cf5b7f8e196a4a61e7c5db9765d8a3bc7a525646fcddc14e
@@ -1 +0,0 @@
1
- 69f08b26cd366c958c137cbeea75c1050a73cc4a84eebbaa953aede65d91bfb7
@@ -1 +0,0 @@
1
- b74fe067e2c2f9272fc4d187704346f583d8d2dd1304d4ecd685cf96bbf59d535d2c1295bd5a36e77371616150c61c2b94b5d85d8a19df5395bacecb118db874
@@ -1 +0,0 @@
1
- c3644a9925737eb7236ba7bb96683e3129a78524ef8ab7db56528c6f9b3b97f9
@@ -1 +0,0 @@
1
- 59e6060c660d6da413f1a6a5300dcc17154bbd00bf389ce6374c1ec903ea434ae6ee23af7a8b93776b13a486cbe77ec4c592cc2c50666cca4fc610c987dcb071