react-native-background-geolocation 5.8.0 → 5.8.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.
@@ -9,7 +9,7 @@ def DEFAULT_TARGET_SDK_VERSION = 35
9
9
 
10
10
  // Plugin dependencies
11
11
  def DEFAULT_PLAY_SERVICES_LOCATION_VERSION = "21.3.0"
12
- def DEFAULT_TSLOCATIONMANAGER_VERSION = "4.7.0"
12
+ def DEFAULT_TSLOCATIONMANAGER_VERSION = "4.7.+"
13
13
  def DEFAULT_OK_HTTP_VERSION = "4.12.0"
14
14
  def DEFAULT_ANDROID_PERMISSIONS_VERSION = "2.1.6"
15
15
  def DEFAULT_EVENTBUS_VERSION = "3.3.1"
@@ -11,7 +11,6 @@
11
11
  #import <ReactCodegen/RNBackgroundGeolocation/RNBackgroundGeolocation.h>
12
12
 
13
13
  #import <React/RCTBridge+Private.h>
14
- #import <React/RCTUtils.h>
15
14
 
16
15
  using namespace facebook;
17
16
  using namespace facebook::react;
@@ -21,6 +20,7 @@ using namespace facebook::react;
21
20
  #import <Foundation/Foundation.h>
22
21
  #import <CoreLocation/CoreLocation.h>
23
22
  #import <UIKit/UIKit.h>
23
+ #import <React/RCTUtils.h>
24
24
  #import <TSLocationManager/TSLocationManager.h>
25
25
 
26
26
  static NSString *const TS_LOCATION_MANAGER_TAG = @"TSLocationManager";
@@ -68,9 +68,12 @@ RCT_EXPORT_MODULE();
68
68
  // TSLocationManager instance
69
69
  locationManager = [TSLocationManager sharedInstance];
70
70
 
71
- // Provide reference to rootViewController for #emailLog method.
72
- UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
73
- locationManager.viewController = root;
71
+ // Provide a view controller for the SDK's alerts. (#2675) UIApplicationDelegate.window is optional: a UIScene
72
+ // app's AppDelegate (React Native 0.88's template) has none, and sending it -window throws. Fall back to the
73
+ // scene's key window.
74
+ id<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
75
+ UIWindow *window = [appDelegate respondsToSelector:@selector(window)] ? appDelegate.window : nil;
76
+ locationManager.viewController = (window ?: RCTKeyWindow()).rootViewController;
74
77
  }
75
78
  return self;
76
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-background-geolocation",
3
- "version": "5.8.0",
3
+ "version": "5.8.1",
4
4
  "description": "The most sophisticated cross-platform background location-tracking & geofencing module with battery-conscious motion-detection intelligence",
5
5
  "scripts": {
6
6
  "build": "pnpm run build:expo",
@@ -230,9 +230,25 @@ export default class NativeModule {
230
230
  return subscription;
231
231
  }
232
232
 
233
+ // @deprecated in favor of subscription.remove().
234
+ // (WO-144) index.js's removeListener() and the shared types still expose this, so it has to exist
235
+ // until they retire it: 5.0 deleted it here alone and the call threw.
236
+ static removeListener(event, callback) {
237
+ 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()');
238
+ const found = findEventSubscriptionByEvent(event, callback);
239
+ if (found !== null) {
240
+ found.subscription.remove();
241
+ return true;
242
+ } else {
243
+ return false;
244
+ }
245
+ }
246
+
233
247
  static removeListeners() {
234
248
  return new Promise((resolve, reject) => {
235
- EVENT_SUBSCRIPTIONS.forEach((sub) => {
249
+ // (WO-096) Walk a copy: each remove() splices EVENT_SUBSCRIPTIONS, and forEach over the live
250
+ // array skips the element after every one it removes.
251
+ EVENT_SUBSCRIPTIONS.slice().forEach((sub) => {
236
252
  sub.subscription.remove();
237
253
  });
238
254
  EVENT_SUBSCRIPTIONS = [];
package/src/index.js CHANGED
@@ -576,9 +576,10 @@ export default class BackgroundGeolocation {
576
576
 
577
577
  /**
578
578
  * Remove geofences. You may either supply an array of identifiers or nothing to destroy all geofences.
579
- * 1. removeGeofences() <-- Promise
579
+ * 1. removeGeofences() <-- Promise: remove all
580
580
  * 2. removeGeofences(['foo']) <-- Promise
581
- * 3. removeGeofences(success, [failure]) <-- v4 callback form: remove all
581
+ * 3. removeGeofences([]) <-- Promise: remove none
582
+ * 4. removeGeofences(success, [failure]) <-- v4 callback form: remove all
582
583
  */
583
584
  static removeGeofences(identifiers, failure) {
584
585
  if (typeof(identifiers) == 'function') {
@@ -587,10 +588,11 @@ export default class BackgroundGeolocation {
587
588
  NativeModule.removeGeofences([]).then(success).catch(failure);
588
589
  return;
589
590
  }
590
- if (identifiers == null) identifiers = [];
591
- // (WO-047) An empty list means "remove all" in both cores: anything malformed must reject,
592
- // never fall through to []. An index loop, not .some(), which skips the holes of a sparse list.
593
- // Covered by tests/remove-geofences.test.js.
591
+ // (WO-055) "All" crosses to native as [], as it does in every release: both cores read an empty list as
592
+ // "remove all".
593
+ if (identifiers == null) return NativeModule.removeGeofences([]);
594
+ // (WO-047) Anything malformed must reject here, never fall through to []. An index loop, not .some(),
595
+ // which skips the holes of a sparse list. Covered by tests/remove-geofences.test.js.
594
596
  let valid = Array.isArray(identifiers);
595
597
  for (let n = 0; valid && n < identifiers.length; n++) {
596
598
  valid = typeof(identifiers[n]) == 'string';
@@ -598,6 +600,8 @@ export default class BackgroundGeolocation {
598
600
  if (!valid) {
599
601
  return Promise.reject(new Error("BackgroundGeolocation#removeGeofences must be provided an {Array} of {String} identifiers, or nothing to remove all geofences."));
600
602
  }
603
+ // (WO-055) An empty list names none. It never crosses to native, where it would remove all.
604
+ if (!identifiers.length) return Promise.resolve(true);
601
605
  return NativeModule.removeGeofences(identifiers);
602
606
  }
603
607