react-native-background-geolocation 5.1.1 → 5.3.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.
package/README.md CHANGED
@@ -57,8 +57,8 @@ See [`/example`](example/README.md) — example apps are included in this repo.
57
57
  | <img src="assets/images/platforms/flutter.svg" width="16" height="16"> [Flutter](https://github.com/transistorsoft/flutter_background_geolocation) | `flutter_background_geolocation` |
58
58
  | <img src="assets/images/platforms/capacitor.svg" width="16" height="16"> [Capacitor](https://github.com/transistorsoft/capacitor-background-geolocation) | `@transistorsoft/capacitor-background-geolocation` |
59
59
  | <img src="assets/images/platforms/cordova.svg" width="16" height="16"> [Cordova](https://github.com/transistorsoft/cordova-background-geolocation-lt) | `cordova-background-geolocation-lt` |
60
- | <img src="assets/images/platforms/swift.svg" width="16" height="16"> [Swift / iOS](https://github.com/transistorsoft/background-geolocation) | `background-geolocation` |
61
- | <img src="assets/images/platforms/kotlin.svg" width="16" height="16"> [Kotlin / Android](https://github.com/transistorsoft/background-geolocation) | `background-geolocation` |
60
+ | <img src="assets/images/platforms/swift.svg" width="16" height="16"> [Swift / iOS](https://github.com/transistorsoft/native-background-geolocation) | `background-geolocation` |
61
+ | <img src="assets/images/platforms/kotlin.svg" width="16" height="16"> [Kotlin / Android](https://github.com/transistorsoft/native-background-geolocation) | `background-geolocation` |
62
62
 
63
63
  ---
64
64
 
@@ -26,7 +26,7 @@ Pod::Spec.new do |s|
26
26
  s.source_files = 'ios/RNBackgroundGeolocation/*.{h,m,mm}'
27
27
  s.preserve_paths = 'docs', 'CHANGELOG.md', 'LICENSE', 'package.json', 'RNBackgroundGeolocation.ios.js'
28
28
 
29
- tslm_version = ENV['TSLOCATIONMANAGER_VERSION'] || '~> 4.1.0'
29
+ tslm_version = ENV['TSLOCATIONMANAGER_VERSION'] || '~> 4.3.0'
30
30
  s.dependency 'TSLocationManager', tslm_version
31
31
 
32
32
  s.libraries = 'sqlite3', 'z', 'stdc++'
@@ -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.1.+"
12
+ def DEFAULT_TSLOCATIONMANAGER_VERSION = "4.3.+"
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"
@@ -25,6 +25,38 @@ def safeExtGet(prop, fallback) {
25
25
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
26
26
  }
27
27
 
28
+ // Guards against the missing-symbol crash that occurs when an app pins an `ext.tslocationmanagerVersion`
29
+ // older than the SDK this plugin's bridge adapter was built against. Returns `minVersion` (with a
30
+ // warning) when the pinned version's entire range is below it; otherwise returns the pin unchanged.
31
+ // Dynamic pins are handled by comparing the pin's ceiling to the minimum's floor, so "4.2.+" is
32
+ // overridden while "4.+"/"+" are respected. Drop-in identical across the four plugin SDKs.
33
+ def ensureTSLocationManagerVersion(String configured, String minVersion) {
34
+ def parse = { String v, boolean asCeiling ->
35
+ def parts = (v ?: "").trim().tokenize(".")
36
+ def out = [0, 0, 0]
37
+ boolean wild = false
38
+ for (int i = 0; i < 3; i++) {
39
+ if (wild) { out[i] = asCeiling ? Integer.MAX_VALUE : 0; continue }
40
+ def p = (i < parts.size()) ? parts[i] : null
41
+ if (p != null && p.isInteger()) {
42
+ out[i] = p as int
43
+ } else if (p != null) { // "+" wildcard or qualifier
44
+ wild = true
45
+ out[i] = asCeiling ? Integer.MAX_VALUE : 0
46
+ } // missing trailing component stays 0
47
+ }
48
+ return out
49
+ }
50
+ def c = parse(configured, true) // ceiling of the app's pin
51
+ def f = parse(minVersion, false) // floor of the required minimum
52
+ def cmp = (c[0] <=> f[0]) ?: (c[1] <=> f[1]) ?: (c[2] <=> f[2])
53
+ if (cmp < 0) {
54
+ println("[tslocationmanager] ⚠️ ext.tslocationmanagerVersion '${configured}' is older than the '${minVersion}' required by this plugin release and has been overridden to '${minVersion}'. The native bridge adapter references symbols added in '${minVersion}'; an older SDK causes missing-symbol build failures / runtime crashes. Update or remove ext.tslocationmanagerVersion in your root build.gradle to silence this warning.")
55
+ return minVersion
56
+ }
57
+ return configured
58
+ }
59
+
28
60
  react {
29
61
  libraryName = "react-native-background-geolocation"
30
62
  codegenJavaPackageName = "com.transistorsoft.rnbackgroundgeolocation"
@@ -61,7 +93,7 @@ repositories{
61
93
 
62
94
  dependencies {
63
95
  def playServicesLocationVersion = safeExtGet('playServicesLocationVersion', safeExtGet('googlePlayServicesLocationVersion', DEFAULT_PLAY_SERVICES_LOCATION_VERSION))
64
- def tslocationmanagerVersion = safeExtGet('tslocationmanagerVersion', DEFAULT_TSLOCATIONMANAGER_VERSION)
96
+ def tslocationmanagerVersion = ensureTSLocationManagerVersion(safeExtGet('tslocationmanagerVersion', DEFAULT_TSLOCATIONMANAGER_VERSION), DEFAULT_TSLOCATIONMANAGER_VERSION)
65
97
  implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
66
98
 
67
99
  def locationMajorVersion = playServicesLocationVersion.split('\\.')[0] as int
@@ -62,6 +62,8 @@ public class HeadlessTask {
62
62
  params = event.getProviderChangeEvent().toMap();
63
63
  } else if (name.equals(EventName.ACTIVITYCHANGE)) {
64
64
  params = event.getActivityChangeEvent().toMap();
65
+ } else if (name.equals(EventName.LOCATIONFILTER)) {
66
+ params = event.getLocationFilterEvent().toMap();
65
67
  } else if (name.equals(EventName.SCHEDULE)) {
66
68
  params = config.toMap(false);
67
69
  } else if (name.equals(EventName.BOOT)) {
@@ -43,10 +43,12 @@ import com.transistorsoft.locationmanager.adapter.BackgroundGeolocation;
43
43
  import com.transistorsoft.locationmanager.adapter.callback.*;
44
44
 
45
45
  import com.transistorsoft.locationmanager.data.LocationModel;
46
+ import com.transistorsoft.locationmanager.data.LocationQuery;
46
47
 
47
48
  import com.transistorsoft.locationmanager.data.SQLQuery;
48
49
  import com.transistorsoft.locationmanager.device.DeviceInfo;
49
50
  import com.transistorsoft.locationmanager.event.ActivityChangeEvent;
51
+ import com.transistorsoft.locationmanager.event.LocationFilterEvent;
50
52
  import com.transistorsoft.locationmanager.event.AuthorizationEvent;
51
53
  import com.transistorsoft.locationmanager.event.ConnectivityChangeEvent;
52
54
  import com.transistorsoft.locationmanager.event.GeofenceEvent;
@@ -118,6 +120,7 @@ public class RNBackgroundGeolocationModule
118
120
  mEvents.add(EventName.LOCATION);
119
121
  mEvents.add(EventName.MOTIONCHANGE);
120
122
  mEvents.add(EventName.ACTIVITYCHANGE);
123
+ mEvents.add(EventName.LOCATIONFILTER);
121
124
  mEvents.add(EventName.PROVIDERCHANGE);
122
125
  mEvents.add(EventName.GEOFENCESCHANGE);
123
126
  mEvents.add(EventName.GEOFENCE);
@@ -146,6 +149,7 @@ public class RNBackgroundGeolocationModule
146
149
  adapter.onLocation(new LocationCallback());
147
150
  adapter.onMotionChange(new MotionChangeCallback());
148
151
  adapter.onActivityChange(new ActivityChangeCallback());
152
+ adapter.onLocationFilter(new LocationFilterCallback());
149
153
  adapter.onLocationProviderChange(new LocationProviderChangeCallback());
150
154
  adapter.onGeofencesChange(new GeofencesChangeCallback());
151
155
  adapter.onGeofence(new GeofenceCallback());
@@ -199,6 +203,15 @@ public class RNBackgroundGeolocationModule
199
203
  }
200
204
  }
201
205
 
206
+ /**
207
+ * locationfilter event callback
208
+ */
209
+ private class LocationFilterCallback implements TSLocationFilterCallback {
210
+ @Override public void onLocationFilter(LocationFilterEvent event) {
211
+ sendEvent(EventName.LOCATIONFILTER, mapToWritableMap(event.toMap()));
212
+ }
213
+ }
214
+
202
215
  /**
203
216
  * providerchange event callback
204
217
  */
@@ -477,8 +490,9 @@ public class RNBackgroundGeolocationModule
477
490
  }
478
491
 
479
492
  @ReactMethod
480
- public void getLocations(final Promise response) {
481
- getAdapter().getLocations(new TSGetLocationsCallback() {
493
+ public void getLocations(ReadableMap params, final Promise response) {
494
+ LocationQuery query = LocationQuery.fromMap(params != null ? params.toHashMap() : null);
495
+ getAdapter().getLocations(query, new TSGetLocationsCallback() {
482
496
  @Override public void onSuccess(List<LocationModel> records) {
483
497
  try {
484
498
  JSONArray data = new JSONArray();
@@ -30,6 +30,7 @@ static NSString *const EVENT_WATCHPOSITION = @"watchposition";
30
30
  static NSString *const EVENT_PROVIDERCHANGE = @"providerchange";
31
31
  static NSString *const EVENT_MOTIONCHANGE = @"motionchange";
32
32
  static NSString *const EVENT_ACTIVITYCHANGE = @"activitychange";
33
+ static NSString *const EVENT_LOCATIONFILTER = @"locationfilter";
33
34
  static NSString *const EVENT_GEOFENCESCHANGE = @"geofenceschange";
34
35
  static NSString *const EVENT_HTTP = @"http";
35
36
  static NSString *const EVENT_SCHEDULE = @"schedule";
@@ -89,6 +90,9 @@ RCT_EXPORT_MODULE();
89
90
  NSDictionary *params = @{@"activity": event.activity, @"confidence": @(event.confidence)};
90
91
  [me sendEvent:EVENT_ACTIVITYCHANGE body:params];
91
92
  }];
93
+ [locationManager onLocationFilter:^(TSLocationFilterEvent *event) {
94
+ [me sendEvent:EVENT_LOCATIONFILTER body:[event toDictionary]];
95
+ }];
92
96
  [locationManager onHeartbeat:^(TSHeartbeatEvent *event) {
93
97
  [me sendEvent:EVENT_HEARTBEAT body:[event toDictionary]];
94
98
  }];
@@ -131,6 +135,7 @@ RCT_EXPORT_MODULE();
131
135
  EVENT_PROVIDERCHANGE,
132
136
  EVENT_MOTIONCHANGE,
133
137
  EVENT_ACTIVITYCHANGE,
138
+ EVENT_LOCATIONFILTER,
134
139
  EVENT_GEOFENCESCHANGE,
135
140
  EVENT_POWERSAVECHANGE,
136
141
  EVENT_HTTP,
@@ -384,9 +389,10 @@ RCT_EXPORT_METHOD(stopWatchPosition:(NSInteger)watchId resolve:(RCTPromiseResolv
384
389
  resolve(@(YES));
385
390
  }
386
391
 
387
- RCT_EXPORT_METHOD(getLocations:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
392
+ RCT_EXPORT_METHOD(getLocations:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
388
393
  {
389
- [locationManager getLocations:^(NSArray* records) {
394
+ LocationQuery *query = [[LocationQuery alloc] initWithDictionary:params];
395
+ [locationManager getLocations:query success:^(NSArray* records) {
390
396
  resolve(records);
391
397
  } failure:^(NSString* error) {
392
398
  reject(@"get_locations_error", error, nil);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "react-native-background-geolocation",
4
- "version": "5.1.1",
4
+ "version": "5.3.0",
5
5
  "description": "The most sophisticated cross-platform background location-tracking & geofencing module with battery-conscious motion-detection intelligence",
6
6
  "scripts": {
7
7
  "build": "yarn run build:expo",
@@ -41,7 +41,7 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "@babel/runtime": "^7.26.0",
44
- "@transistorsoft/background-geolocation-types": "^5.1.0",
44
+ "@transistorsoft/background-geolocation-types": "^5.2.0",
45
45
  "tslib": "^2.6.3"
46
46
  },
47
47
  "author": "Chris Scott <chris@transistorsoft.com>",
@@ -330,8 +330,8 @@ export default class NativeModule {
330
330
  * HTTP & Persistence Methods
331
331
  */
332
332
 
333
- static getLocations() {
334
- return RNBackgroundGeolocation.getLocations();
333
+ static getLocations(query) {
334
+ return RNBackgroundGeolocation.getLocations(query || {});
335
335
  }
336
336
 
337
337
  static getCount() {
package/src/index.js CHANGED
@@ -89,6 +89,7 @@ export default class BackgroundGeolocation {
89
89
  static get EVENT_HEARTBEAT() { return Event.Heartbeat; }
90
90
  static get EVENT_PROVIDERCHANGE() { return Event.ProviderChange; }
91
91
  static get EVENT_ACTIVITYCHANGE() { return Event.ActivityChange; }
92
+ static get EVENT_LOCATIONFILTER() { return Event.LocationFilter; }
92
93
  static get EVENT_GEOFENCE() { return Event.Geofence; }
93
94
  static get EVENT_GEOFENCESCHANGE() { return Event.GeofencesChange; }
94
95
  static get EVENT_ENABLEDCHANGE() { return Event.EnabledChange; }
@@ -275,6 +276,10 @@ export default class BackgroundGeolocation {
275
276
  return this.addListener(Event.ActivityChange, callback);
276
277
  }
277
278
 
279
+ static onLocationFilter(callback) {
280
+ return this.addListener(Event.LocationFilter, callback);
281
+ }
282
+
278
283
  static onGeofence(callback) {
279
284
  return this.addListener(Event.Geofence, callback);
280
285
  }
@@ -434,8 +439,8 @@ export default class BackgroundGeolocation {
434
439
  * HTTP & Persistence
435
440
  *
436
441
  */
437
- static getLocations() {
438
- return NativeModule.getLocations();
442
+ static getLocations(query) {
443
+ return NativeModule.getLocations(query);
439
444
  }
440
445
 
441
446
  /**
@@ -21,7 +21,7 @@ export interface Spec extends TurboModule {
21
21
  setOdometer(value: number): Promise<Object>;
22
22
 
23
23
  // HTTP & DB
24
- getLocations(): Promise<Array<Object>>;
24
+ getLocations(query: Object): Promise<Array<Object>>;
25
25
  getCount(): Promise<number>;
26
26
  destroyLocations(): Promise<void>;
27
27
  sync(): Promise<Array<Object>>;
@@ -28,7 +28,7 @@ export interface Spec extends TurboModule {
28
28
  +getState: () => Promise<Object>;
29
29
 
30
30
  // Locations / persistence
31
- +getLocations: () => Promise<Array<Object>>;
31
+ +getLocations: (query: Object) => Promise<Array<Object>>;
32
32
  +getCount: () => Promise<Int32>;
33
33
  +insertLocation: (params: Object) => Promise<string>;
34
34
 
@@ -0,0 +1,30 @@
1
+ jest.mock('../src/NativeModule', () => ({
2
+ addListener: jest.fn(() => ({ remove: jest.fn() })),
3
+ }));
4
+
5
+ const NativeModule = require('../src/NativeModule');
6
+ const BG = require('../src/index.js').default;
7
+ const Shared = require('@transistorsoft/background-geolocation-types');
8
+
9
+ // onLocationFilter event wiring (issue #2585).
10
+ test('exposes the locationfilter event name + subscription method', () => {
11
+ // Shared enum carries the new event name.
12
+ expect(Shared.Event.LocationFilter).toBe('locationfilter');
13
+
14
+ // Backward-compat static getter mirrors the shared enum.
15
+ expect(BG.EVENT_LOCATIONFILTER).toBe('locationfilter');
16
+
17
+ // Subscription method is exposed.
18
+ expect(typeof BG.onLocationFilter).toBe('function');
19
+ });
20
+
21
+ test('onLocationFilter routes through the native bridge with the locationfilter event', () => {
22
+ NativeModule.addListener.mockClear();
23
+ const cb = jest.fn();
24
+
25
+ const subscription = BG.onLocationFilter(cb);
26
+
27
+ expect(NativeModule.addListener).toHaveBeenCalledWith('locationfilter', cb);
28
+ expect(subscription).toBeDefined();
29
+ expect(typeof subscription.remove).toBe('function');
30
+ });