react-native-background-geolocation 5.0.0-beta.4 → 5.0.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.
@@ -11,7 +11,7 @@ body:
11
11
  id: terms
12
12
  attributes:
13
13
  label: Required Reading
14
- description: "- I have read the Wikis [Philosophy of Operation](../wiki/Philosophy-of-Operation) and [Debugging](../wiki/Debugging)\n- I am aware of the [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation/)\n- I am aware of the [CHANGELOG](../blob/master/CHANGELOG.md)"
14
+ description: "- I have read the Wikis [Philosophy of Operation](./wiki/Philosophy-of-Operation) and [Debugging](./wiki/Debugging)\n- I am aware of the [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation/)\n- I am aware of the [CHANGELOG](./blob/master/CHANGELOG.md)"
15
15
  options:
16
16
  - label: Confirmed
17
17
  required: true
@@ -11,7 +11,7 @@ body:
11
11
  id: terms
12
12
  attributes:
13
13
  label: Required Reading
14
- description: "- I have read the Wikis [Philosophy of Operation](../wiki/Philosophy-of-Operation) and [Debugging](../wiki/Debugging)\n- I am aware of the [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation/)\n- I am aware of the [CHANGELOG](../blob/master/CHANGELOG.md)"
14
+ description: "- I have read the Wikis [Philosophy of Operation](./wiki/Philosophy-of-Operation) and [Debugging](./wiki/Debugging)\n- I am aware of the [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation/)\n- I am aware of the [CHANGELOG](./blob/master/CHANGELOG.md)"
15
15
  options:
16
16
  - label: Confirmed
17
17
  required: true
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  | <img src="https://dl.dropbox.com/s/gxl3sr8znhkrtah/expo-logo.png?dl=1" alt="alt text" width="32" /> | Now with *Expo* support |
2
2
  | --- | --- |
3
3
 
4
+
4
5
  Background Geolocation for React Native &middot; [![npm](https://img.shields.io/npm/dm/react-native-background-geolocation.svg)]() [![npm](https://img.shields.io/npm/v/react-native-background-geolocation.svg)]()
5
6
  ============================================================================
6
7
 
@@ -16,7 +17,7 @@ The plugin's [Philosophy of Operation](../../wiki/Philosophy-of-Operation) is to
16
17
 
17
18
  - When the device is detected be **stationary**, the plugin will automatically turn off location-services to conserve energy.
18
19
 
19
- Also available for [Flutter](https://github.com/transistorsoft/flutter_background_geolocation), [Cordova](https://github.com/transistorsoft/cordova-background-geolocation-lt), [NativeScript](https://github.com/transistorsoft/nativescript-background-geolocation-lt) and pure native apps.
20
+ Also available for [Flutter](https://github.com/transistorsoft/flutter_background_geolocation), [Cordova](https://github.com/transistorsoft/cordova-background-geolocation-lt), [Capacitor](https://github.com/transistorsoft/capacitor-background-geolocation) and pure native apps.
20
21
 
21
22
  > [!NOTE]
22
23
  > The **[Android module](http://www.transistorsoft.com/shop/products/react-native-background-geolocation)** requires [purchasing a license](http://www.transistorsoft.com/shop/products/react-native-background-geolocation). However, it *will* work for **DEBUG** builds. It will **not** work with **RELEASE** builds [without purchasing a license](http://www.transistorsoft.com/shop/products/react-native-background-geolocation). This plugin is supported **full-time** and field-tested **daily** since 2013.
@@ -28,9 +29,12 @@ Also available for [Flutter](https://github.com/transistorsoft/flutter_backgroun
28
29
  ![Home](https://dl.dropboxusercontent.com/s/wa43w1n3xhkjn0i/home-framed-350.png?dl=1)
29
30
  ![Settings](https://dl.dropboxusercontent.com/s/8oad228siog49kt/settings-framed-350.png?dl=1)
30
31
 
32
+ > [!CAUTION]
33
+ > This README references the new __`v5.x`__ branch of the SDK. If you're using __`v4.x`__, you must reference [__`v4.x`__](https://github.com/transistorsoft/react-native-background-geolocation/tree/4.19.4) branch.
34
+
31
35
  # Contents
32
36
  - ### 😫 [Help!](../../wiki/Help)
33
- - ### :books: [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation/5.0.0-beta)
37
+ - ### :books: [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation/latest)
34
38
  - ### [Installing the Plugin](#large_blue_diamond-installing-the-plugin)
35
39
  - ### [Setup Guides](#large_blue_diamond-setup-guides)
36
40
  - ### [Configure your License](#large_blue_diamond-configure-your-license)
@@ -43,22 +47,25 @@ Also available for [Flutter](https://github.com/transistorsoft/flutter_backgroun
43
47
 
44
48
  ## :large_blue_diamond: Installing the Plugin
45
49
 
50
+ > [!CAUTION]
51
+ > This is the new v5 version. For previous version, see [`v4.x`](https://github.com/transistorsoft/react-native-background-geolocation/tree/4.19.4). __`v4.x`__ license keys do not work with __`v5`__. Login to the customer dashboard to generate a __`v5`__ key.
52
+
46
53
 
47
54
  ### With *Expo*
48
55
 
49
56
  ```shell
50
- npx expo install react-native-background-geolocation@beta
57
+ npx expo install react-native-background-geolocation
51
58
  ```
52
59
 
53
60
  ### With `yarn`
54
61
 
55
62
  ```bash
56
- yarn add react-native-background-geolocation@beta
63
+ yarn add react-native-background-geolocation
57
64
  ```
58
65
 
59
66
  ### With `npm`
60
67
  ```
61
- $ npm install react-native-background-geolocation@beta --save
68
+ $ npm install react-native-background-geolocation --save
62
69
  ```
63
70
 
64
71
  ## :large_blue_diamond: Setup Guides
@@ -79,7 +86,7 @@ $ npm install react-native-background-geolocation@beta --save
79
86
  [www.transistorsoft.com/shop/customers](http://www.transistorsoft.com/shop/customers)
80
87
  ![](https://gallery.mailchimp.com/e932ea68a1cb31b9ce2608656/images/b2696718-a77e-4f50-96a8-0b61d8019bac.png)
81
88
 
82
- 2. Add your license-key to `android/app/src/main/AndroidManifest.xml`:
89
+ 2. __`[Android]`__ Add your license-key to `android/app/src/main/AndroidManifest.xml`:
83
90
 
84
91
  ```diff
85
92
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
@@ -93,7 +100,7 @@ $ npm install react-native-background-geolocation@beta --save
93
100
  android:theme="@style/AppTheme">
94
101
 
95
102
  <!-- react-native-background-geolocation licence -->
96
- + <meta-data android:name="com.transistorsoft.locationmanager.license" android:value="YOUR_LICENCE_KEY_HERE" />
103
+ + <meta-data android:name="com.transistorsoft.locationmanager.license" android:value="YOUR_ANDROID_LICENCE_KEY_HERE" />
97
104
  .
98
105
  .
99
106
  .
@@ -101,36 +108,20 @@ $ npm install react-native-background-geolocation@beta --save
101
108
  </manifest>
102
109
  ```
103
110
 
104
- ## :large_blue_diamond: Using the plugin ##
111
+ 3. __`[iOS]`__ Add your license-key to your __`Info.plist`__
105
112
 
106
- ```javascript
107
- import BackgroundGeolocation from "react-native-background-geolocation";
108
- ```
113
+ | Key | Type | Value |
114
+ |-----|-------|-------------|
115
+ | *`TSLocationManagerLicense`* | `String` | ` <PASTE YOUR IOS LICENSE KEY HERE> ` |
109
116
 
110
- ### [Typescript](https://facebook.github.io/react-native/blog/2018/05/07/using-typescript-with-react-native) API:
117
+ __`TSLocationManagerLicense`__. Paste the contents of your license key into the __`value`__.
111
118
 
112
- For those using [Typescript](https://facebook.github.io/react-native/blog/2018/05/07/using-typescript-with-react-native) (__recommended__), you can also `import` the interfaces:
113
- ```javascript
114
- import BackgroundGeolocation, {
115
- State,
116
- Config,
117
- Location,
118
- LocationError,
119
- Geofence,
120
- GeofenceEvent,
121
- GeofencesChangeEvent,
122
- HeartbeatEvent,
123
- HttpEvent,
124
- MotionActivityEvent,
125
- MotionChangeEvent,
126
- ProviderChangeEvent,
127
- ConnectivityChangeEvent
128
- } from "react-native-background-geolocation";
119
+ ## :large_blue_diamond: Using the plugin ##
129
120
 
121
+ ```javascript
122
+ import BackgroundGeolocation from "react-native-background-geolocation";
130
123
  ```
131
124
 
132
- For more information, see [this blog post](https://medium.com/@transistorsoft/new-feature-typescript-api-4a160a2c853b)
133
-
134
125
  ## :large_blue_diamond: Example
135
126
 
136
127
  There are three main steps to using `BackgroundGeolocation`
@@ -139,32 +130,29 @@ There are three main steps to using `BackgroundGeolocation`
139
130
  3. `.start()` the plugin.
140
131
 
141
132
  > [!WARNING]
142
- > Do not execute *any* API method which will require accessing location-services until the **[`.ready(config)`](https://transistorsoft.github.io/react-native-background-geolocation/classes/backgroundgeolocation.html#ready)** method resolves ([Read its API docs](https://transistorsoft.github.io/react-native-background-geolocation/classes/backgroundgeolocation.html#ready)), For example:
133
+ > Do not execute *any* API method which will require accessing location-services until the **[`.ready(config)`](https://transistorsoft.github.io/react-native-background-geolocation/latest/interfaces/BackgroundGeolocation.html#ready)** method resolves ([Read its API docs](https://transistorsoft.github.io/react-native-background-geolocation/latest/interfaces/BackgroundGeolocation.html#ready)), For example:
143
134
  >- `.getCurrentPosition`
144
135
  >- `.watchPosition`
145
136
  >- `.start`
146
137
 
147
138
  ```javascript
148
139
  // NO! .ready() has not resolved.
149
- BackgroundGeolocation.getCurrentPosition(options);
150
- BackgroundGeolocation.start();
140
+ await BackgroundGeolocation.getCurrentPosition(options);
141
+ await BackgroundGeolocation.start();
142
+
143
+ // First call .ready(config)
144
+ const state = await BackgroundGeolocation.ready(config);
145
+ const location = await BackgroundGeolocation.getCurrentPosition(options);
146
+ await BackgroundGeolocation.start();
151
147
 
152
- BackgroundGeolocation.ready(config).then((state) => {
153
- // YES -- .ready() has now resolved.
154
- BackgroundGeolocation.getCurrentPosition(options);
155
- BackgroundGeolocation.start();
156
- });
157
148
 
158
149
  // NO! .ready() has not resolved.
159
- BackgroundGeolocation.getCurrentPosition(options);
160
- BackgroundGeolocation.start();
150
+ const location = await BackgroundGeolocation.getCurrentPosition(options);
151
+ await BackgroundGeolocation.start();
161
152
  ```
162
153
 
163
154
 
164
- ### Example 1. &mdash; React *Functional Component*
165
-
166
- <details>
167
- <summary>Show Source</summary>
155
+ ### Example
168
156
 
169
157
  ```javascript
170
158
 
@@ -206,24 +194,32 @@ const HelloWorld = () => {
206
194
  /// 2. ready the plugin.
207
195
  BackgroundGeolocation.ready({
208
196
  // Geolocation Config
209
- desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
210
- distanceFilter: 10,
211
- // Activity Recognition
212
- stopTimeout: 5,
213
- // Application config
214
- debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
215
- logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
216
- stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
217
- startOnBoot: true, // <-- Auto start tracking when device is powered-up.
218
- // HTTP / SQLite config
219
- url: 'http://yourserver.com/locations',
220
- batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
221
- autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
222
- headers: { // <-- Optional HTTP headers
223
- "X-FOO": "bar"
197
+ geolocation: {
198
+ desiredAccuracy: BackgroundGeolocation.DesiredAccuracy.High
199
+ distanceFilter: 10,
200
+ stopTimeout: 5
201
+ },
202
+ // Logger Config
203
+ logger: {
204
+ debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
205
+ logLevel: BackgroundGeolocation.LogLevel.Verbose
224
206
  },
225
- params: { // <-- Optional HTTP params
226
- "auth_token": "maybe_your_server_authenticates_via_token_YES?"
207
+ // Application config
208
+ app: {
209
+ stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
210
+ startOnBoot: true // <-- Auto start tracking when device is powered-up.
211
+ },
212
+ // Http Config
213
+ http: {
214
+ url: 'http://yourserver.com/locations',
215
+ batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
216
+ autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
217
+ headers: { // <-- Optional HTTP headers
218
+ "X-FOO": "bar"
219
+ },
220
+ params: { // <-- Optional HTTP params
221
+ "auth_token": "maybe_your_server_authenticates_via_token_YES?"
222
+ }
227
223
  }
228
224
  }).then((state) => {
229
225
  setEnabled(state.enabled)
@@ -263,157 +259,10 @@ const HelloWorld = () => {
263
259
  export default HelloWorld;
264
260
  ```
265
261
 
266
- </details>
267
-
268
- ### Example 2. &mdash; React *Class Component*
269
-
270
- <details>
271
- <summary>Show Source</summary>
272
-
273
- ```javascript
274
- import React from 'react';
275
- import {
276
- Switch,
277
- Text,
278
- View,
279
- } from 'react-native';
280
-
281
- import BackgroundGeolocation, {
282
- Location,
283
- Subscription
284
- } from "react-native-background-geolocation";
285
-
286
- export default class HelloWorld extends React.Component {
287
- subscriptions:Subscription[] = [];
288
- state:any = {};
289
- constructor(props:any) {
290
- super(props);
291
- this.state = {
292
- enabled: false,
293
- location: ''
294
- }
295
- }
296
-
297
- componentDidMount() {
298
- /// 1. Subscribe to BackgroundGeolocation events.
299
- this.subscriptions.push(BackgroundGeolocation.onLocation((location) => {
300
- console.log('[onLocation]', location);
301
- this.setState({location: JSON.stringify(location, null, 2)})
302
- }, (error) => {
303
- console.log('[onLocation] ERROR:', error);
304
- }))
305
-
306
- this.subscriptions.push(BackgroundGeolocation.onMotionChange((event) => {
307
- console.log('[onMotionChange]', event);
308
- }))
309
-
310
- this.subscriptions.push(BackgroundGeolocation.onActivityChange((event) => {
311
- console.log('[onActivityChange]', event);
312
- }))
313
-
314
- this.subscriptions.push(BackgroundGeolocation.onProviderChange((event) => {
315
- console.log('[onProviderChange]', event);
316
- }))
317
-
318
- /// 2. ready the plugin.
319
- BackgroundGeolocation.ready({
320
- // Geolocation Config
321
- desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
322
- distanceFilter: 10,
323
- // Activity Recognition
324
- stopTimeout: 5,
325
- // Application config
326
- debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
327
- logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
328
- stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
329
- startOnBoot: true, // <-- Auto start tracking when device is powered-up.
330
- // HTTP / SQLite config
331
- url: 'http://yourserver.com/locations',
332
- batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
333
- autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
334
- headers: { // <-- Optional HTTP headers
335
- "X-FOO": "bar"
336
- },
337
- params: { // <-- Optional HTTP params
338
- "auth_token": "maybe_your_server_authenticates_via_token_YES?"
339
- }
340
- }).then((state) => {
341
- this.setState({enabled: state.enabled});
342
- console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
343
- })
344
- }
345
-
346
- /// When view is destroyed (or refreshed during development live-reload),
347
- /// remove BackgroundGeolocation event subscriptions.
348
- componentWillUnmount() {
349
- this.subscriptions.forEach((subscription) => subscription.remove());
350
- }
351
-
352
- onToggleEnabled(value:boolean) {
353
- console.log('[onToggleEnabled]', value);
354
- this.setState({enabled: value})
355
- if (value) {
356
- BackgroundGeolocation.start();
357
- } else {
358
- this.setState({location: ''});
359
- BackgroundGeolocation.stop();
360
- }
361
- }
362
-
363
- render() {
364
- return (
365
- <View style={{alignItems:'center'}}>
366
- <Text>Click to enable BackgroundGeolocation</Text>
367
- <Switch value={this.state.enabled} onValueChange={this.onToggleEnabled.bind(this)} />
368
- <Text style={{fontFamily:'monospace', fontSize:12}}>{this.state.location}</Text>
369
- </View>
370
- )
371
- }
372
- }
373
- ```
374
- </details>
375
-
376
- ### Promise API
377
-
378
- The `BackgroundGeolocation` Javascript API supports [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) for *nearly* every method (the exceptions are **`#watchPosition`** and adding event-listeners via **`#onXXX`** method (eg: `onLocation`). For more information, see the [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation-android)
379
-
380
- ```javascript
381
- BackgroundGeolocation.ready({
382
- desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
383
- distanceFilter: 50
384
- }).then(state => {
385
- console.log('- BackgroundGeolocation is ready: ', state);
386
- }).catch(error => {
387
- console.warn('- BackgroundGeolocation error: ', error);
388
- });
389
-
390
- // Or use await in an async function
391
- try {
392
- const state = await BackgroundGeolocation.ready({
393
- desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
394
- distanceFilter: 50
395
- })
396
- console.log('- BackgroundGeolocation is ready: ', state);
397
- } catch (error) {
398
- console.warn('- BackgroundGeolocation error: ', error);
399
- }
400
- ```
401
-
402
- ## :large_blue_diamond: [Demo Application](https://github.com/transistorsoft/rn-background-geolocation-demo)
403
-
404
- A fully-featured [Demo App](https://github.com/transistorsoft/rn-background-geolocation-demo) is available in its own public repo. After first cloning that repo, follow the installation instructions in the **README** there. This demo-app includes a settings-screen allowing you to quickly experiment with all the different settings available for each platform.
405
-
406
- ![Home](https://dl.dropboxusercontent.com/s/wa43w1n3xhkjn0i/home-framed-350.png?dl=1)
407
- ![Settings](https://dl.dropboxusercontent.com/s/8oad228siog49kt/settings-framed-350.png?dl=1)
408
-
409
-
410
- ## :large_blue_diamond: [Simple Testing Server](https://github.com/transistorsoft/background-geolocation-console)
411
-
412
- A simple Node-based [web-application](https://github.com/transistorsoft/background-geolocation-console) with SQLite database is available for field-testing and performance analysis. If you're familiar with Node, you can have this server up-and-running in about **one minute**.
262
+ ## :large_blue_diamond: [Demo Application](example)
413
263
 
414
- ![](https://dl.dropboxusercontent.com/s/px5rzz7wybkv8fs/background-geolocation-console-map.png?dl=1)
264
+ Clone this repo and run the [/example](example) app.
415
265
 
416
- ![](https://dl.dropboxusercontent.com/s/tiy5b2oivt0np2y/background-geolocation-console-grid.png?dl=1)
417
266
 
418
267
  # License
419
268
 
@@ -27,7 +27,7 @@ Pod::Spec.new do |s|
27
27
  s.preserve_paths = 'docs', 'CHANGELOG.md', 'LICENSE', 'package.json', 'RNBackgroundGeolocation.ios.js'
28
28
 
29
29
  s.dependency 'CocoaLumberjack', '~> 3.8.5'
30
- s.dependency 'TSLocationManager', '~> 4.0.0-beta.5'
30
+ s.dependency 'TSLocationManager', '~> 4.0.0'
31
31
 
32
32
  s.libraries = 'sqlite3', 'z', 'stdc++'
33
33
  s.resource_bundles = {
@@ -42,4 +42,4 @@ Pod::Spec.new do |s|
42
42
  else
43
43
  s.dependency 'React-Core'
44
44
  end
45
- end
45
+ end
@@ -9,6 +9,7 @@ def DEFAULT_TARGET_SDK_VERSION = 36
9
9
 
10
10
  // Plugin dependencies
11
11
  def DEFAULT_PLAY_SERVICES_LOCATION_VERSION = "21.3.0"
12
+ def DEFAULT_TSLOCATIONMANAGER_VERSION = "4.0.+"
12
13
  def DEFAULT_OK_HTTP_VERSION = "4.12.0"
13
14
  def DEFAULT_ANDROID_PERMISSIONS_VERSION = "2.1.6"
14
15
  def DEFAULT_EVENTBUS_VERSION = "3.3.1"
@@ -60,9 +61,16 @@ repositories{
60
61
 
61
62
  dependencies {
62
63
  def playServicesLocationVersion = safeExtGet('playServicesLocationVersion', safeExtGet('googlePlayServicesLocationVersion', DEFAULT_PLAY_SERVICES_LOCATION_VERSION))
63
-
64
+ def tslocationmanagerVersion = safeExtGet('tslocationmanagerVersion', DEFAULT_TSLOCATIONMANAGER_VERSION)
64
65
  implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
65
- implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
66
- implementation "com.transistorsoft:tslocationmanager:4.0.0-beta.+"
66
+
67
+ def locationMajorVersion = playServicesLocationVersion.split('\\.')[0] as int
68
+ if (locationMajorVersion >= 21) {
69
+ api "com.transistorsoft:tslocationmanager:$tslocationmanagerVersion"
70
+ } else {
71
+ api "com.transistorsoft:tslocationmanager-gms20:$tslocationmanagerVersion"
72
+ }
73
+
74
+ implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
67
75
  implementation 'org.greenrobot:eventbus:3.3.1'
68
76
  }
@@ -39,7 +39,7 @@ public class HeadlessTask {
39
39
  TSConfig config = TSConfig.getInstance(event.getContext());
40
40
 
41
41
  String name = event.getName();
42
- TSLog.logger.debug("\uD83D\uDC80 event: " + name);
42
+ TSLog.d("\uD83D\uDC80 event: " + name);
43
43
 
44
44
  WritableMap clientEvent = new WritableNativeMap();
45
45
  Map<String, ?> params = null;
@@ -83,7 +83,7 @@ public class HeadlessTask {
83
83
  } else if (name.equals(EventName.AUTHORIZATION)) {
84
84
  params = event.getAuthorizationEvent().toMap();
85
85
  } else {
86
- TSLog.logger.warn(TSLog.warn("Unknown Headless Event: " + name));
86
+ TSLog.w(TSLog.warn("Unknown Headless Event: " + name));
87
87
  clientEvent.putString("error", "Unknown event: " + name);
88
88
  clientEvent.putNull("params");
89
89
  }
@@ -98,18 +98,18 @@ public class HeadlessTask {
98
98
  .setParams(clientEvent)
99
99
  .setTimeout(TASK_TIMEOUT)
100
100
  .setOnInvokeCallback((reactContext, task) -> {
101
- //TSLog.logger.debug("*** onInvoke: " + task.getId());
101
+ //TSLog.d("*** onInvoke: " + task.getId());
102
102
  })
103
103
  .setOnFinishCallback(taskId -> {
104
- //TSLog.logger.debug("*** onFinish: " + taskId);
104
+ //TSLog.d("*** onFinish: " + taskId);
105
105
  })
106
106
  .setOnErrorCallback((task, e) -> {
107
- TSLog.logger.warn("⚠\uFE0F HeadlessTaskError: " + e.getMessage() + ": " + task.toString());
107
+ TSLog.w("⚠\uFE0F HeadlessTaskError: " + e.getMessage() + ": " + task.toString());
108
108
  })
109
109
  .build()
110
110
  );
111
111
  } catch (Exception e) {
112
- TSLog.logger.warn(TSLog.warn("Failed invoke HeadlessTask " + name + ". Task ignored: " + e.getMessage()));
112
+ TSLog.w("Failed invoke HeadlessTask " + name + ". Task ignored: " + e.getMessage());
113
113
  e.printStackTrace();
114
114
  }
115
115
  }
@@ -124,7 +124,7 @@ public class HeadlessTask {
124
124
  try {
125
125
  HeadlessTaskManager.getInstance().finishTask(event.getContext(), event.getTaskId());
126
126
  } catch (Exception e) {
127
- TSLog.logger.warn(TSLog.warn(e.getMessage()));
127
+ TSLog.w(e.getMessage());
128
128
  }
129
129
  }
130
130
  }
@@ -161,7 +161,7 @@ public class HeadlessTaskManager implements HeadlessJsTaskEventListener {
161
161
  removeTask(task);
162
162
  task.onFinish();
163
163
 
164
- TSLog.logger.debug("[onHeadlessJsTaskFinish] taskId: " + taskId);
164
+ TSLog.d("[onHeadlessJsTaskFinish] taskId: " + taskId);
165
165
  }
166
166
 
167
167
  private ReactNativeHost getReactNativeHost(Context context) {
@@ -189,7 +189,7 @@ public class HeadlessTaskManager implements HeadlessJsTaskEventListener {
189
189
  Method getCurrentReactContext = reactHost.getClass().getMethod("getCurrentReactContext");
190
190
  return (ReactContext) getCurrentReactContext.invoke(reactHost);
191
191
  } catch (Exception e) {
192
- TSLog.logger.error(TSLog.error( "Reflection error getCurrentReactContext: " + e.getMessage()), e);
192
+ TSLog.e(TSLog.error( "Reflection error getCurrentReactContext: " + e.getMessage()), e);
193
193
  }
194
194
  }
195
195
  final ReactInstanceManager reactInstanceManager = getReactNativeHost(context).getReactInstanceManager();
@@ -206,7 +206,7 @@ public class HeadlessTaskManager implements HeadlessJsTaskEventListener {
206
206
  return;
207
207
  }
208
208
  if (mIsInitializingReactContext.compareAndSet(false, true)) {
209
- TSLog.logger.debug( "[createReactContextAndScheduleTask] initialize ReactContext");
209
+ TSLog.d( "[createReactContextAndScheduleTask] initialize ReactContext");
210
210
  final Object reactHost = getReactHost(context);
211
211
  if (isBridglessArchitectureEnabled()) { // NEW arch
212
212
  ReactInstanceEventListener callback = new ReactInstanceEventListener() {
@@ -218,7 +218,7 @@ public class HeadlessTaskManager implements HeadlessJsTaskEventListener {
218
218
  Method removeReactInstanceEventListener = reactHost.getClass().getMethod("removeReactInstanceEventListener", ReactInstanceEventListener.class);
219
219
  removeReactInstanceEventListener.invoke(reactHost, this);
220
220
  } catch (Exception e) {
221
- TSLog.logger.error(TSLog.error("HeadlessTask reflection error removeReactInstanceEventListener: ") + e);
221
+ TSLog.e(TSLog.error("HeadlessTask reflection error removeReactInstanceEventListener: ") + e);
222
222
  }
223
223
  }
224
224
  };
@@ -228,7 +228,7 @@ public class HeadlessTaskManager implements HeadlessJsTaskEventListener {
228
228
  Method startReactHost = reactHost.getClass().getMethod("start");
229
229
  startReactHost.invoke(reactHost);
230
230
  } catch (Exception e) {
231
- TSLog.logger.error(TSLog.error("HeadlessTask reflection error ReactHost start: " + e.getMessage()), e);
231
+ TSLog.e(TSLog.error("HeadlessTask reflection error ReactHost start: " + e.getMessage()), e);
232
232
  }
233
233
  } else { // OLD arch
234
234
  final ReactInstanceManager reactInstanceManager = getReactNativeHost(context).getReactInstanceManager();
@@ -363,7 +363,7 @@ public class HeadlessTaskManager implements HeadlessJsTaskEventListener {
363
363
 
364
364
  boolean invoke(ReactContext reactContext) throws IllegalStateException {
365
365
  if (mReactTaskId > 0) {
366
- TSLog.logger.warn(TSLog.warn("Task already invoked <IGNORED>: " + this));
366
+ TSLog.w(TSLog.warn("Task already invoked <IGNORED>: " + this));
367
367
  return true;
368
368
  }
369
369
  HeadlessJsTaskContext headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext);
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
- "name": "react-native-background-geolocation",
3
- "version": "5.0.0-beta.4",
2
+
3
+ "name": "react-native-background-geolocation",
4
+ "version": "5.0.1",
4
5
  "description": "The most sophisticated cross-platform background location-tracking & geofencing module with battery-conscious motion-detection intelligence",
6
+ "scripts": {
7
+ "build": "yarn run build:expo",
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build:expo": "rimraf expo/plugin/build && tsc --build ./expo/plugin",
10
+ "docs": "node ./scripts/generate-docs.mjs",
11
+ "docs:publish": "./scripts/publish-docs.sh",
12
+ "prepublishOnly": "npm run build"
13
+ },
5
14
  "codegenConfig": {
6
15
  "name": "RNBackgroundGeolocation",
7
16
  "type": "modules",
@@ -12,7 +21,7 @@
12
21
  "ios": {
13
22
  "swiftModuleName": "RNBackgroundGeolocation",
14
23
  "packageName": "RNBackgroundGeolocation"
15
- }
24
+ }
16
25
  },
17
26
  "main": "src/index.js",
18
27
  "repository": {
@@ -50,12 +59,5 @@
50
59
  "rimraf": "^5.0.0",
51
60
  "typedoc": "^0.28.14",
52
61
  "typescript": "^5.6.0"
53
- },
54
- "scripts": {
55
- "build": "yarn run build:expo",
56
- "test": "echo \"Error: no test specified\" && exit 1",
57
- "build:expo": "rimraf expo/plugin/build && tsc --build ./expo/plugin",
58
- "docs": "node ./scripts/generate-docs.mjs",
59
- "docs:publish": "./scripts/publish-docs.sh"
60
62
  }
61
- }
63
+ }
package/src/Logger.js CHANGED
@@ -3,8 +3,6 @@
3
3
 
4
4
  import NativeModule from "./NativeModule";
5
5
 
6
- const RNBackgroundGeolocation = NativeModule; // uses the same getNativeBGGeo() under the hood
7
-
8
6
  const LOG_LEVEL_DEBUG = "debug";
9
7
  const LOG_LEVEL_NOTICE = "notice";
10
8
  const LOG_LEVEL_INFO = "info";
@@ -15,12 +13,19 @@ const ORDER_ASC = 1;
15
13
  const ORDER_DESC = -1;
16
14
 
17
15
  function log(level, msg) {
18
- // You can either:
19
- // 1) call the native logger via NativeModule.logger
20
- // NativeModule.logger[level](msg);
21
- // or
22
- // 2) just use the native `log` directly if exposed:
23
- RNBackgroundGeolocation.log(level, msg);
16
+ // Call the native logger via NativeModule.logger[level](msg),
17
+ // fallback to debug if missing.
18
+ if (
19
+ NativeModule.logger &&
20
+ typeof NativeModule.logger[level] === 'function'
21
+ ) {
22
+ NativeModule.logger[level](msg);
23
+ } else if (
24
+ NativeModule.logger &&
25
+ typeof NativeModule.logger.debug === 'function'
26
+ ) {
27
+ NativeModule.logger.debug(msg);
28
+ }
24
29
  }
25
30
 
26
31
  function validateQuery(query) {
@@ -45,18 +50,18 @@ export default class Logger {
45
50
  static notice(msg) { log(LOG_LEVEL_NOTICE, msg); }
46
51
 
47
52
  static getLog(query) {
48
- return RNBackgroundGeolocation.getLog(validateQuery(query));
53
+ return NativeModule.getLog(validateQuery(query));
49
54
  }
50
55
 
51
56
  static emailLog(email, query) {
52
- return RNBackgroundGeolocation.emailLog(email, validateQuery(query));
57
+ return NativeModule.emailLog(email, validateQuery(query));
53
58
  }
54
59
 
55
60
  static uploadLog(url, query) {
56
- return RNBackgroundGeolocation.uploadLog(url, validateQuery(query));
61
+ return NativeModule.uploadLog(url, validateQuery(query));
57
62
  }
58
63
 
59
64
  static destroyLog() {
60
- return RNBackgroundGeolocation.destroyLog();
65
+ return NativeModule.destroyLog();
61
66
  }
62
67
  }
@@ -395,16 +395,20 @@ export default class NativeModule {
395
395
  return RNBackgroundGeolocation.setLogLevel(value);
396
396
  }
397
397
 
398
- static getLog() {
399
- return RNBackgroundGeolocation.getLog();
398
+ static getLog(query) {
399
+ return RNBackgroundGeolocation.getLog(query);
400
400
  }
401
401
 
402
402
  static destroyLog() {
403
- return RNBackgroundGeolocation.destroyLog();
403
+ return RNBackgroundGeolocation.destroyLog();
404
404
  }
405
405
 
406
406
  static emailLog(email, query) {
407
- return RNBackgroundGeolocation.emailLog(email, query);
407
+ return RNBackgroundGeolocation.emailLog(email, query);
408
+ }
409
+
410
+ static uploadLog(url, query) {
411
+ return RNBackgroundGeolocation.uploadLog(url, query);
408
412
  }
409
413
 
410
414
  static isPowerSaveMode() {
@@ -35,6 +35,11 @@ declare module "react-native-background-geolocation" {
35
35
  * - [[getOdometer]]
36
36
  */
37
37
  odometer: number;
38
+ /**
39
+ * The estimated error (in meters) of the current odometer value.
40
+ */
41
+ odometerError: number;
42
+
38
43
  /**
39
44
  * `true` when the iOS app was launched in the background. Always `false` for Android.
40
45
  * iOS apps can be launched in the background due to a background-fetch event, geofence events or exiting the [[Config.stationaryRadius]].
@@ -44,6 +44,10 @@ export interface Spec extends TurboModule {
44
44
 
45
45
  // Logging
46
46
  log(level: string, message: string): Promise<void>;
47
+ getLog(query: Object): Promise<string>;
48
+ emailLog(email: string, query: Object): Promise<void>;
49
+ uploadLog(url: string, query: Object): Promise<void>;
50
+ destroyLog(): Promise<void>;
47
51
  }
48
52
 
49
53
  export default TurboModuleRegistry.getEnforcing<Spec>('RNBackgroundGeolocation');