react-native-background-geolocation 4.4.0 → 4.4.4

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 (39) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +209 -61
  3. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.aar +0 -0
  4. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.aar.md5 +1 -0
  5. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.aar.sha1 +1 -0
  6. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.aar.sha256 +1 -0
  7. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.aar.sha512 +1 -0
  8. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.pom +9 -0
  9. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.pom.md5 +1 -0
  10. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.pom.sha1 +1 -0
  11. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.pom.sha256 +1 -0
  12. package/android/libs/com/transistorsoft/tslocationmanager/3.1.35/tslocationmanager-3.1.35.pom.sha512 +1 -0
  13. package/android/libs/com/transistorsoft/tslocationmanager/maven-metadata.xml +4 -6
  14. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.aar +0 -0
  15. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.aar.md5 +1 -0
  16. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.aar.sha1 +1 -0
  17. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.aar.sha256 +1 -0
  18. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.aar.sha512 +1 -0
  19. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.pom +9 -0
  20. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.pom.md5 +1 -0
  21. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.pom.sha1 +1 -0
  22. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.pom.sha256 +1 -0
  23. package/android/libs/com/transistorsoft/tslocationmanager-reverse/3.1.35/tslocationmanager-reverse-3.1.35.pom.sha512 +1 -0
  24. package/android/libs/com/transistorsoft/tslocationmanager-reverse/maven-metadata.xml +4 -6
  25. package/android/src/main/java/com/transistorsoft/rnbackgroundgeolocation/RNBackgroundGeolocationModule.java +17 -13
  26. package/ios/RNBackgroundGeolocation/RNBackgroundGeolocation.m +7 -7
  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/declarations/BackgroundGeolocation.d.ts +52 -32
  39. package/src/declarations/interfaces/Subscription.d.ts +104 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.4.4 — 2021-11-11
4
+ * [Fixed][iOS] More issues with iOS plugin 'invalidate' method. Get rid of this method. Implement startObserving, stopObserving.
5
+
6
+ ## 4.4.3 — 2021-11-10
7
+ * [Fixed][iOS] Backwards compatibility issue: react-native@0.66 does have this method. `No visible @interface for 'RCTEventEmitter' declares the selector 'invalidate' in RNBackgroundGeolocation.m`.
8
+
9
+ ## 4.4.2 — 2021-10-29
10
+ * [Fixed][Android] Android 12 behaviour changes mean that foreground-services remain running. When an Android app is terminated, the app process does not terminate (since the foreground-service is active) and `RNBackgroundGeolocationModule` remains in memory. Given that, the plugin cannot rely on registering its event-listeners in the `RNBackgroundGeolocationModule` constructor, but must perform that task when `.ready()` is called. This also requires resetting `mReady = false` when the `MainActivity` is destroyed, so that the next time `.ready()` is called, the event-listeners are re-registered.
11
+ * [Fixed][Android] When `.ready()` is called __`reset: false`__, the `success` callback was not invoked with the current `State`. This bug was introduced in previous `v4.4.1`.
12
+
13
+ ## 4.4.1 — 2021-10-29
14
+ * [Added] Added a `Subscription` interface to Typescript API. Added helpful docs to Subscription for new event-handler subscriptions.
15
+
16
+ ```typescript
17
+ import BackgroundGeolocation, {
18
+ Subscription
19
+ } from "...";
20
+ .
21
+ .
22
+ .
23
+ const subscription:Subscription = BacckgroundGeolocation.onLocation(myHandler);
24
+ ```
25
+
3
26
  ## 4.4.0 — 2021-10-25
4
27
  * [Added] New `Authorization.strategy "SAS"` (alternative to default `JWT`).
5
28
  * [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`.
package/README.md CHANGED
@@ -29,6 +29,7 @@ The **[Android module](http://www.transistorsoft.com/shop/products/react-native-
29
29
  ![Settings](https://dl.dropboxusercontent.com/s/8oad228siog49kt/settings-framed-350.png?dl=1)
30
30
 
31
31
  # Contents
32
+ - ### 😫 [Help!](../../wiki/Help)
32
33
  - ### :books: [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation)
33
34
  - ### [Installing the Plugin](#large_blue_diamond-installing-the-plugin)
34
35
  - ### [Setup Guides](#large_blue_diamond-setup-guides)
@@ -136,40 +137,77 @@ For more information, see [this blog post](https://medium.com/@transistorsoft/ne
136
137
 
137
138
  There are three main steps to using `BackgroundGeolocation`
138
139
  1. Wire up event-listeners.
139
- 2. `#ready` the plugin.
140
- 3. `#start` the plugin.
140
+ 2. `.ready(config)` the plugin.
141
+ 3. `.start()` the plugin.
142
+
143
+ :warning: Do not execute *any* API method which will require accessing location-services until the **`.ready(config)`** method resolves (eg: `#getCurrentPosition`, `#watchPosition`, `#start`).
141
144
 
142
145
  ```javascript
143
- // Import BackgroundGeolocation + any optional interfaces
144
- import BackgroundGeolocation from "react-native-background-geolocation";
146
+ // NO! .ready() has not resolved.
147
+ BackgroundGeolocation.getCurrentPosition(options);
148
+ BackgroundGeolocation.start();
149
+
150
+ BackgroundGeolocation.ready(config).then((state) => {
151
+ // YES -- .ready() has now resolved.
152
+ BackgroundGeolocation.getCurrentPosition(options);
153
+ BackgroundGeolocation.start();
154
+ });
155
+
156
+ // NO! .ready() has not resolved.
157
+ BackgroundGeolocation.getCurrentPosition(options);
158
+ BackgroundGeolocation.start();
159
+ ```
145
160
 
146
- export default class App extends Component {
147
- componentWillMount() {
148
- ////
149
- // 1. Wire up event-listeners
150
- //
151
161
 
152
- // This handler fires whenever bgGeo receives a location update.
153
- BackgroundGeolocation.onLocation(this.onLocation, this.onError);
162
+ ### Example 1. — React *Functional Component*
154
163
 
155
- // This handler fires when movement states changes (stationary->moving; moving->stationary)
156
- BackgroundGeolocation.onMotionChange(this.onMotionChange);
164
+ <details>
165
+ <summary>Show Source</summary>
157
166
 
158
- // This event fires when a change in motion activity is detected
159
- BackgroundGeolocation.onActivityChange(this.onActivityChange);
167
+ ```javascript
168
+
169
+ import React from 'react';
170
+ import {
171
+ Switch,
172
+ Text,
173
+ View,
174
+ } from 'react-native';
160
175
 
161
- // This event fires when the user toggles location-services authorization
162
- BackgroundGeolocation.onProviderChange(this.onProviderChange);
176
+ import BackgroundGeolocation, {
177
+ Location,
178
+ Subscription
179
+ } from "react-native-background-geolocation";
163
180
 
164
- ////
165
- // 2. Execute #ready method (required)
166
- //
181
+ const HelloWorld = () => {
182
+ const [enabled, setEnabled] = React.useState(false);
183
+ const [location, setLocation] = React.useState('');
184
+
185
+ React.useEffect(() => {
186
+ /// 1. Subscribe to events.
187
+ const onLocation:Subscription = BackgroundGeolocation.onLocation((location) => {
188
+ console.log('[onLocation]', location);
189
+ setLocation(JSON.stringify(location, null, 2));
190
+ })
191
+
192
+ const onMotionChange:Subscription = BackgroundGeolocation.onMotionChange((event) => {
193
+ console.log('[onMotionChange]', event);
194
+ });
195
+
196
+ const onActivityChange:Subscription = BackgroundGeolocation.onActivityChange((event) => {
197
+ console.log('[onMotionChange]', event);
198
+ })
199
+
200
+ const onProviderChange:Subscription = BackgroundGeolocation.onProviderChange((event) => {
201
+ console.log('[onProviderChange]', event);
202
+ })
203
+
204
+ /// 2. ready the plugin.
167
205
  BackgroundGeolocation.ready({
168
206
  // Geolocation Config
169
207
  desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
170
208
  distanceFilter: 10,
171
209
  // Activity Recognition
172
- stopTimeout: 1,
210
+ stopTimeout: 5,
173
211
  // Application config
174
212
  debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
175
213
  logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
@@ -185,68 +223,178 @@ export default class App extends Component {
185
223
  params: { // <-- Optional HTTP params
186
224
  "auth_token": "maybe_your_server_authenticates_via_token_YES?"
187
225
  }
188
- }, (state) => {
226
+ }).then((state) => {
227
+ setEnabled(state.enabled)
189
228
  console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
229
+ });
230
+
231
+ return () => {
232
+ // Remove BackgroundGeolocation event-subscribers when the View is removed or refreshed
233
+ // during development live-reload. Without this, event-listeners will accumulate with
234
+ // each refresh during live-reload.
235
+ onLocation.remove();
236
+ onMotionChange.remove();
237
+ onActivityChange.remove();
238
+ onProviderChange.remove();
239
+ }
240
+ }, []);
241
+
242
+ /// 3. start / stop BackgroundGeolocation
243
+ React.useEffect(() => {
244
+ if (enabled) {
245
+ BackgroundGeolocation.start();
246
+ } else {
247
+ BackgroundGeolocation.stop();
248
+ setLocation('');
249
+ }
250
+ }, [enabled]);
251
+
252
+ return (
253
+ <View style={{alignItems:'center'}}>
254
+ <Text>Click to enable BackgroundGeolocation</Text>
255
+ <Switch value={enabled} onValueChange={setEnabled} />
256
+ <Text style={{fontFamily:'monospace', fontSize:12}}>{location}</Text>
257
+ </View>
258
+ )
259
+ }
190
260
 
191
- if (!state.enabled) {
192
- ////
193
- // 3. Start tracking!
194
- //
195
- BackgroundGeolocation.start(function() {
196
- console.log("- Start success");
197
- });
261
+ export default HelloWorld;
262
+ ```
263
+
264
+ </details>
265
+
266
+ ### Example 2. &mdash; React *Class Component*
267
+
268
+ <details>
269
+ <summary>Show Source</summary>
270
+
271
+ ```javascript
272
+ import React from 'react';
273
+ import {
274
+ Switch,
275
+ Text,
276
+ View,
277
+ } from 'react-native';
278
+
279
+ import BackgroundGeolocation, {
280
+ Location,
281
+ Subscription
282
+ } from "react-native-background-geolocation";
283
+
284
+ export default class HelloWorld extends React.Component {
285
+ subscriptions:Subscription[] = [];
286
+ state:any = {};
287
+ constructor(props:any) {
288
+ super(props);
289
+ this.state = {
290
+ enabled: false,
291
+ location: ''
292
+ }
293
+ }
294
+
295
+ componentDidMount() {
296
+ /// 1. Subscribe to BackgroundGeolocation events.
297
+ this.subscriptions.push(BackgroundGeolocation.onLocation((location) => {
298
+ console.log('[onLocation]', location);
299
+ this.setState({location: JSON.stringify(location, null, 2)})
300
+ }, (error) => {
301
+ console.log('[onLocation] ERROR:', error);
302
+ }))
303
+
304
+ this.subscriptions.push(BackgroundGeolocation.onMotionChange((event) => {
305
+ console.log('[onMotionChange]', event);
306
+ }))
307
+
308
+ this.subscriptions.push(BackgroundGeolocation.onActivityChange((event) => {
309
+ console.log('[onActivityChange]', event);
310
+ }))
311
+
312
+ this.subscriptions.push(BackgroundGeolocation.onProviderChange((event) => {
313
+ console.log('[onProviderChange]', event);
314
+ }))
315
+
316
+ /// 2. ready the plugin.
317
+ BackgroundGeolocation.ready({
318
+ // Geolocation Config
319
+ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
320
+ distanceFilter: 10,
321
+ // Activity Recognition
322
+ stopTimeout: 5,
323
+ // Application config
324
+ debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
325
+ logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
326
+ stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
327
+ startOnBoot: true, // <-- Auto start tracking when device is powered-up.
328
+ // HTTP / SQLite config
329
+ url: 'http://yourserver.com/locations',
330
+ batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
331
+ autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
332
+ headers: { // <-- Optional HTTP headers
333
+ "X-FOO": "bar"
334
+ },
335
+ params: { // <-- Optional HTTP params
336
+ "auth_token": "maybe_your_server_authenticates_via_token_YES?"
198
337
  }
199
- });
338
+ }).then((state) => {
339
+ this.setState({enabled: state.enabled});
340
+ console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
341
+ })
200
342
  }
201
343
 
202
- // You must remove listeners when your component unmounts
344
+ /// When view is destroyed (or refreshed during development live-reload),
345
+ /// remove BackgroundGeolocation event subscriptions.
203
346
  componentWillUnmount() {
204
- BackgroundGeolocation.removeListeners();
205
- }
206
- onLocation(location) {
207
- console.log('[location] -', location);
208
- }
209
- onError(error) {
210
- console.warn('[location] ERROR -', error);
211
- }
212
- onActivityChange(event) {
213
- console.log('[activitychange] -', event); // eg: 'on_foot', 'still', 'in_vehicle'
347
+ this.subscriptions.forEach((subscription) => subscription.remove());
214
348
  }
215
- onProviderChange(provider) {
216
- console.log('[providerchange] -', provider.enabled, provider.status);
349
+
350
+ onToggleEnabled(value:boolean) {
351
+ console.log('[onToggleEnabled]', value);
352
+ this.setState({enabled: value})
353
+ if (value) {
354
+ BackgroundGeolocation.start();
355
+ } else {
356
+ this.setState({location: ''});
357
+ BackgroundGeolocation.stop();
358
+ }
217
359
  }
218
- onMotionChange(event) {
219
- console.log('[motionchange] -', event.isMoving, event.location);
360
+
361
+ render() {
362
+ return (
363
+ <View style={{alignItems:'center'}}>
364
+ <Text>Click to enable BackgroundGeolocation</Text>
365
+ <Switch value={this.state.enabled} onValueChange={this.onToggleEnabled.bind(this)} />
366
+ <Text style={{fontFamily:'monospace', fontSize:12}}>{this.state.location}</Text>
367
+ </View>
368
+ )
220
369
  }
221
370
  }
222
-
223
- ```
224
-
225
- ```javascript
226
- BackgroundGeolocation.ready({
227
- reset: true, // <-- true to always apply the supplied config
228
- distanceFilter: 10
229
- }, (state) => {
230
- console.log('- BackgroundGeolocation is ready: ', state);
231
- });
232
371
  ```
233
-
234
- :warning: Do not execute *any* API method which will require accessing location-services until the callback to **`#ready`** executes (eg: `#getCurrentPosition`, `#watchPosition`, `#start`).
372
+ </details>
235
373
 
236
374
  ### Promise API
237
375
 
238
- 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 **`#on`** method. For more information, see the [API Documentation](https://transistorsoft.github.io/react-native-background-geolocation)
376
+ 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)
239
377
 
240
378
  ```javascript
241
- // Traditional API still works:
242
379
  BackgroundGeolocation.ready({
243
- desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
380
+ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
244
381
  distanceFilter: 50
245
382
  }).then(state => {
246
383
  console.log('- BackgroundGeolocation is ready: ', state);
247
384
  }).catch(error => {
248
- console.log('- BackgroundGeolocation error: ', error);
385
+ console.warn('- BackgroundGeolocation error: ', error);
249
386
  });
387
+
388
+ // Or use await in an async function
389
+ try {
390
+ const state = await BackgroundGeolocation.ready({
391
+ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
392
+ distanceFilter: 50
393
+ })
394
+ console.log('- BackgroundGeolocation is ready: ', state);
395
+ } catch (error) {
396
+ console.warn('- BackgroundGeolocation error: ', error);
397
+ }
250
398
  ```
251
399
 
252
400
  ## :large_blue_diamond: [Demo Application](https://github.com/transistorsoft/rn-background-geolocation-demo)
@@ -0,0 +1 @@
1
+ c16850b24271032c3ccb10349ba0774069a67819
@@ -0,0 +1 @@
1
+ e18fc8dd9d37cd2ee00c64e8e1a78ebc0839cf8515cf52463cfdd0761aa580f9
@@ -0,0 +1 @@
1
+ 566d4327d7b1b9ab3b271dc61d6d661ac1f4c8c89557de1d11c52928a4af5682c702a315e76f2cf46dc882d405fe3c4d6a958c7f0a885a228b3d0b2a735d8305
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4
+ <modelVersion>4.0.0</modelVersion>
5
+ <groupId>com.transistorsoft</groupId>
6
+ <artifactId>tslocationmanager</artifactId>
7
+ <version>3.1.35</version>
8
+ <packaging>aar</packaging>
9
+ </project>
@@ -0,0 +1 @@
1
+ a558cd1eb103134e207932ea7af8c6cf48cc97d7
@@ -0,0 +1 @@
1
+ f11bf76c75d7d586ceef2978d3bb789deceee30b6c06032edf57647333f98efe
@@ -0,0 +1 @@
1
+ d7d2120c48292dc74e273daacad40b19ebfa0617aed7f8fa3b9a8eeb4a10b0ab85e2cc702394f9d1aaf0619b3fdcef728db223c76ffca66288033eb867787acb
@@ -3,13 +3,11 @@
3
3
  <groupId>com.transistorsoft</groupId>
4
4
  <artifactId>tslocationmanager</artifactId>
5
5
  <versioning>
6
- <latest>3.1.34</latest>
7
- <release>3.1.34</release>
6
+ <latest>3.1.35</latest>
7
+ <release>3.1.35</release>
8
8
  <versions>
9
- <version>3.1.32</version>
10
- <version>3.1.33</version>
11
- <version>3.1.34</version>
9
+ <version>3.1.35</version>
12
10
  </versions>
13
- <lastUpdated>20211013180057</lastUpdated>
11
+ <lastUpdated>20211110133724</lastUpdated>
14
12
  </versioning>
15
13
  </metadata>
@@ -0,0 +1 @@
1
+ 1230b611eb4b11c8a65f878e8253cea9f510fac5979f250014c37dc800645054
@@ -0,0 +1 @@
1
+ 650b7213bc570d2a8697550f5a03ca42657c190a37c490a82fc762d88d6fe5f1170cba23f68530d90180c19ac795c69142b9d39290495a119314163d1ff9577f
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4
+ <modelVersion>4.0.0</modelVersion>
5
+ <groupId>com.transistorsoft</groupId>
6
+ <artifactId>tslocationmanager-reverse</artifactId>
7
+ <version>3.1.35</version>
8
+ <packaging>aar</packaging>
9
+ </project>
@@ -0,0 +1 @@
1
+ 5ee1b9a1bf97d7ea8e005f108f18ec78e2410dfdc45a6e29755a28e5df15daf1
@@ -0,0 +1 @@
1
+ db1bf3fe2779d75145bcf1929692b5a87e24f9d4046d783a40d903eb7ef0a780f26062c03be017b2a9bb759778b9969eebda9b952abde90ac9e0dd37912d728f
@@ -3,13 +3,11 @@
3
3
  <groupId>com.transistorsoft</groupId>
4
4
  <artifactId>tslocationmanager-reverse</artifactId>
5
5
  <versioning>
6
- <latest>3.1.34</latest>
7
- <release>3.1.34</release>
6
+ <latest>3.1.35</latest>
7
+ <release>3.1.35</release>
8
8
  <versions>
9
- <version>3.1.32</version>
10
- <version>3.1.33</version>
11
- <version>3.1.34</version>
9
+ <version>3.1.35</version>
12
10
  </versions>
13
- <lastUpdated>20211013180057</lastUpdated>
11
+ <lastUpdated>20211110133724</lastUpdated>
14
12
  </versioning>
15
13
  </metadata>
@@ -90,13 +90,14 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
90
90
 
91
91
  public RNBackgroundGeolocationModule(ReactApplicationContext reactContext) {
92
92
  super(reactContext);
93
+ reactContext.addLifecycleEventListener(this);
93
94
 
94
95
  TSConfig config = TSConfig.getInstance(getReactApplicationContext());
95
96
  config.useCLLocationAccuracy(true);
96
97
 
97
98
  config.updateWithBuilder()
98
- .setHeadlessJobService(getClass().getPackage().getName() + "." + JOB_SERVICE_CLASS)
99
- .commit();
99
+ .setHeadlessJobService(getClass().getPackage().getName() + "." + JOB_SERVICE_CLASS)
100
+ .commit();
100
101
 
101
102
  // These are the only events which can be subscribed to.
102
103
  mEvents.add(BackgroundGeolocation.EVENT_LOCATION);
@@ -113,9 +114,18 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
113
114
  mEvents.add(BackgroundGeolocation.EVENT_ENABLEDCHANGE);
114
115
  mEvents.add(BackgroundGeolocation.EVENT_NOTIFICATIONACTION);
115
116
  mEvents.add(TSAuthorization.NAME);
117
+ }
116
118
 
117
- reactContext.addLifecycleEventListener(this);
119
+ @Override
120
+ public void initialize() {
121
+ // do nothing
122
+ }
123
+ @Override
124
+ public String getName() {
125
+ return "RNBackgroundGeolocation";
126
+ }
118
127
 
128
+ private void registerEvents() {
119
129
  BackgroundGeolocation adapter = getAdapter();
120
130
  adapter.onLocation(new LocationCallback());
121
131
  adapter.onMotionChange(new MotionChangeCallback());
@@ -133,16 +143,6 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
133
143
  HttpService.getInstance(getReactApplicationContext()).onAuthorization(new AuthorizationCallback());
134
144
  }
135
145
 
136
- @Override
137
- public void initialize() {
138
- // do nothing
139
- }
140
- @Override
141
- public String getName() {
142
- return "RNBackgroundGeolocation";
143
- }
144
-
145
-
146
146
  /**
147
147
  * location event callback
148
148
  */
@@ -340,6 +340,7 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
340
340
  @Override
341
341
  public void onHostDestroy() {
342
342
  mInitialized = false;
343
+ mReady = false;
343
344
  removeAllListeners();
344
345
  getAdapter().onActivityDestroy();
345
346
  }
@@ -374,10 +375,13 @@ public class RNBackgroundGeolocationModule extends ReactContextBaseJavaModule im
374
375
  setConfig(params, success, failure);
375
376
  } else {
376
377
  TSLog.logger.warn(TSLog.warn("#ready already called. Ignored config since reset: false"));
378
+ success.invoke(getState());
377
379
  }
378
380
  return;
379
381
  }
380
382
  mReady = true;
383
+ registerEvents();
384
+
381
385
  if (config.isFirstBoot()) {
382
386
  config.updateWithJSONObject(mapToJson(setHeadlessJobService(params)));
383
387
  } else {
@@ -659,13 +659,13 @@ RCT_EXPORT_METHOD(playSound:(int)soundId)
659
659
  [self sendEventWithName:event body:body];
660
660
  }
661
661
 
662
- - (void)invalidate
663
- {
664
- [super invalidate];
665
- [locationManager removeListeners];
666
- dispatch_async(dispatch_get_main_queue(), ^{
667
- [self.locationManager stopWatchPosition];
668
- });
662
+ - (void) startObserving {
663
+ // TODO Could possibly execute [self registerEventListeners] here.
664
+ [locationManager log:@"info" message:@"[RNBackgroundGeolocation startObserving]"];
665
+ }
666
+ - (void) stopObserving {
667
+ // TODO Could possibly execute [locationManager removeListeners] here.
668
+ [locationManager log:@"info" message:@"[RNBackgroundGeolocation stopObserving]"];
669
669
  }
670
670
 
671
671
  - (void)dealloc
@@ -6,47 +6,47 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_i386_x86_64-simulator</string>
9
+ <string>ios-arm64_x86_64-maccatalyst</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>i386</string>
16
15
  <string>x86_64</string>
17
16
  </array>
18
17
  <key>SupportedPlatform</key>
19
18
  <string>ios</string>
20
19
  <key>SupportedPlatformVariant</key>
21
- <string>simulator</string>
20
+ <string>maccatalyst</string>
22
21
  </dict>
23
22
  <dict>
24
23
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_armv7</string>
24
+ <string>ios-arm64_i386_x86_64-simulator</string>
26
25
  <key>LibraryPath</key>
27
26
  <string>TSLocationManager.framework</string>
28
27
  <key>SupportedArchitectures</key>
29
28
  <array>
30
29
  <string>arm64</string>
31
- <string>armv7</string>
30
+ <string>i386</string>
31
+ <string>x86_64</string>
32
32
  </array>
33
33
  <key>SupportedPlatform</key>
34
34
  <string>ios</string>
35
+ <key>SupportedPlatformVariant</key>
36
+ <string>simulator</string>
35
37
  </dict>
36
38
  <dict>
37
39
  <key>LibraryIdentifier</key>
38
- <string>ios-arm64_x86_64-maccatalyst</string>
40
+ <string>ios-arm64_armv7</string>
39
41
  <key>LibraryPath</key>
40
42
  <string>TSLocationManager.framework</string>
41
43
  <key>SupportedArchitectures</key>
42
44
  <array>
43
45
  <string>arm64</string>
44
- <string>x86_64</string>
46
+ <string>armv7</string>
45
47
  </array>
46
48
  <key>SupportedPlatform</key>
47
49
  <string>ios</string>
48
- <key>SupportedPlatformVariant</key>
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
- lCvkm6gOxhn5NxMHGiCuBZPRf6w=
141
+ Wmf3yVcUbx+t9XH4ju46ia3KxCE=
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>20G165</string>
6
+ <string>21A559</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.7</string>
20
+ <string>4.1.0</string>
21
21
  <key>CFBundleSupportedPlatforms</key>
22
22
  <array>
23
23
  <string>MacOSX</string>
24
24
  </array>
25
25
  <key>CFBundleVersion</key>
26
- <string>381</string>
26
+ <string>382</string>
27
27
  <key>DTCompiler</key>
28
28
  <string>com.apple.compilers.llvm.clang.1_0</string>
29
29
  <key>DTPlatformBuild</key>
30
- <string>12D4e</string>
30
+ <string>13A1030d</string>
31
31
  <key>DTPlatformName</key>
32
32
  <string>macosx</string>
33
33
  <key>DTPlatformVersion</key>
34
- <string>11.1</string>
34
+ <string>12.0</string>
35
35
  <key>DTSDKBuild</key>
36
- <string>20C63</string>
36
+ <string>21A344</string>
37
37
  <key>DTSDKName</key>
38
- <string>macosx11.1</string>
38
+ <string>macosx12.0</string>
39
39
  <key>DTXcode</key>
40
- <string>1240</string>
40
+ <string>1310</string>
41
41
  <key>DTXcodeBuild</key>
42
- <string>12D4e</string>
42
+ <string>13A1030d</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.4.0",
3
+ "version": "4.4.4",
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"
@@ -46,7 +46,7 @@
46
46
  "react-native-background-fetch": "~4.0.4"
47
47
  },
48
48
  "devDependencies": {
49
- "@transistorsoft/typedoc-theme": "^2.0.7",
49
+ "@transistorsoft/typedoc-theme": "^2.0.8",
50
50
  "chalk": "^4.1.0",
51
51
  "fs-extra": "^9.1.0",
52
52
  "rimraf": "^3.0.2"
@@ -23,7 +23,7 @@
23
23
  /// <reference path="interfaces/Authorization.d.ts" />
24
24
  /// <reference path="interfaces/AuthorizationEvent.d.ts" />
25
25
  /// <reference path="interfaces/TransistorAuthorizationToken.d.ts" />
26
- ///
26
+ /// <reference path="interfaces/Subscription.d.ts" />
27
27
  declare module "react-native-background-geolocation" {
28
28
  /**
29
29
  * Primary API of the SDK.
@@ -253,6 +253,23 @@ declare module "react-native-background-geolocation" {
253
253
  */
254
254
  static on(event: string, success:Function, failure?:Function):void;
255
255
  /**
256
+ * @deprecated. Use [[Subscription]] returned from __`BackgroundGeolocation.onXXX`__ to remove listeners.
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * const subscription = BackgroundGeolocation.onLocation((location) => {
261
+ * console.log('[onLocation]', location);
262
+ * });
263
+ * .
264
+ * .
265
+ * .
266
+ * // Remove listener
267
+ * subscription.remove();
268
+ * ```
269
+ *
270
+ * ---------------------------------------------------------------------
271
+ * ### ⚠️ [Deprecated]
272
+ *
256
273
  * Removes an event listener. You must supply the *type* of event to remove in addition to a reference to the *exact* function you
257
274
  * used to subscribe to the event.
258
275
  *
@@ -274,7 +291,7 @@ declare module "react-native-background-geolocation" {
274
291
  *
275
292
  * @example
276
293
  * ```typescript
277
- * let locationHandler = (location) => {
294
+ * const locationHandler = (location) => {
278
295
  * console.log("[location] - ", location)
279
296
  * }
280
297
  * BackgroundGeolocation.onLocation(locationHandler)
@@ -293,7 +310,9 @@ declare module "react-native-background-geolocation" {
293
310
  static un(event: string, handler: Function, success?:Function, failure?:Function): void;
294
311
 
295
312
  /**
296
- * Removes all event-listeners
313
+ * Removes all event-listeners.
314
+ *
315
+ * Calls [[Subscription.remove]] on all subscriptions.
297
316
  *
298
317
  * @example
299
318
  * ```typescript
@@ -314,7 +333,7 @@ declare module "react-native-background-geolocation" {
314
333
  *
315
334
  * @example
316
335
  * ```typescript
317
- * BackgroundGeolocation.onLocation((location) => {
336
+ * const subscription = BackgroundGeolocation.onLocation((location) => {
318
337
  * console.log("[onLocation] success: ", location);
319
338
  * }, (error) => {
320
339
  * console.log("[onLocation] ERROR: ", error);
@@ -333,7 +352,7 @@ declare module "react-native-background-geolocation" {
333
352
  *
334
353
  * @event location
335
354
  */
336
- static onLocation(success: (location:Location)=>void, failure?:(errorCode: LocationError) => void):void;
355
+ static onLocation(success: (location:Location)=>void, failure?:(errorCode: LocationError) => void):Subscription;
337
356
 
338
357
  /**
339
358
  * Subscribe to Geofence transition events.
@@ -342,7 +361,7 @@ declare module "react-native-background-geolocation" {
342
361
  *
343
362
  * @example
344
363
  * ```typescript
345
- * BackgroundGeolocation.onGeofence((event) => {
364
+ * const subscription = BackgroundGeolocation.onGeofence((event) => {
346
365
  * console.log("[onGeofence] ", event);
347
366
  * });
348
367
  * ```
@@ -352,7 +371,7 @@ declare module "react-native-background-geolocation" {
352
371
  *
353
372
  * @event geofence
354
373
  */
355
- static onGeofence(callback: (event: GeofenceEvent) => void):void;
374
+ static onGeofence(callback: (event: GeofenceEvent) => void):Subscription;
356
375
 
357
376
  /**
358
377
  * Subscribe to __`motionchange`__ events.
@@ -362,7 +381,7 @@ declare module "react-native-background-geolocation" {
362
381
  *
363
382
  * @example
364
383
  * ```typescript
365
- * BackgroundGeolocation.onMotionChange((event) => {
384
+ * const subscription = BackgroundGeolocation.onMotionChange((event) => {
366
385
  * if (event.isMoving) {
367
386
  * console.log("[onMotionChange] Device has just started MOVING ", event.location);
368
387
  * } else {
@@ -385,14 +404,14 @@ declare module "react-native-background-geolocation" {
385
404
  *
386
405
  * @event motionchange
387
406
  */
388
- static onMotionChange(callback: (event:MotionChangeEvent) => void): void;
407
+ static onMotionChange(callback: (event:MotionChangeEvent) => void): Subscription;
389
408
 
390
409
  /**
391
410
  * Subscribe to HTTP responses from your server [[Config.url]].
392
411
  *
393
412
  * @example
394
413
  * ```typescript
395
- * BackgroundGeolocation.onHttp((response) => {
414
+ * const subscription = BackgroundGeolocation.onHttp((response) => {
396
415
  * let status = response.status;
397
416
  * let success = response.success;
398
417
  * let responseText = response.responseText;
@@ -404,7 +423,7 @@ declare module "react-native-background-geolocation" {
404
423
  *
405
424
  * @event http
406
425
  */
407
- static onHttp(callback: (response:HttpEvent) => void): void;
426
+ static onHttp(callback: (response:HttpEvent) => void): Subscription;
408
427
 
409
428
  /**
410
429
  * Subscribe to changes in motion activity.
@@ -416,13 +435,13 @@ declare module "react-native-background-geolocation" {
416
435
  *
417
436
  * @example
418
437
  * ```typescript
419
- * BackgroundGeolocation.onActivityChange((event) => {
438
+ * const subscription = BackgroundGeolocation.onActivityChange((event) => {
420
439
  * console.log("[onActivityChange] ", event);
421
440
  * });
422
441
  * ```
423
442
  * @event activitychange
424
443
  */
425
- static onActivityChange(callback: (event: MotionActivityEvent) => void): void;
444
+ static onActivityChange(callback: (event: MotionActivityEvent) => void): Subscription;
426
445
 
427
446
  /**
428
447
  * Subscribe to changes in device's location-services configuration / authorization.
@@ -431,7 +450,7 @@ declare module "react-native-background-geolocation" {
431
450
  *
432
451
  * @example
433
452
  * ```typescript
434
- * BackgroundGeolocation.onProviderChange((event) => {
453
+ * const subscription = BackgroundGeolocation.onProviderChange((event) => {
435
454
  * console.log("[onProviderChange: ", event);
436
455
  *
437
456
  * switch(event.status) {
@@ -459,7 +478,7 @@ declare module "react-native-background-geolocation" {
459
478
  *
460
479
  * @event providerchange
461
480
  */
462
- static onProviderChange(callback: (event:ProviderChangeEvent) => void): void;
481
+ static onProviderChange(callback: (event:ProviderChangeEvent) => void): Subscription;
463
482
 
464
483
  /**
465
484
  * Subscribe to periodic heartbeat events.
@@ -469,10 +488,11 @@ declare module "react-native-background-geolocation" {
469
488
  * @example
470
489
  * ```typescript
471
490
  * BackgroundGeolocation.ready({
472
- * heartbeatInterval: 60
491
+ * heartbeatInterval: 60,
492
+ * preventSuspend: true // <-- Required for iOS
473
493
  * });
474
494
  *
475
- * BackgroundGeolocation.onHeartbeat((event) => {
495
+ * const subscription = BackgroundGeolocation.onHeartbeat((event) => {
476
496
  * console.log("[onHeartbeat] ", event);
477
497
  *
478
498
  * // You could request a new location if you wish.
@@ -489,7 +509,7 @@ declare module "react-native-background-geolocation" {
489
509
  * - The [[Location]] provided by the [[HeartbeatEvent]] is only the last-known location. The *heartbeat* event does not actively engage location-services. If you wish to get the current location in your `callback`, use [[getCurrentPosition]].
490
510
  * @event heartbeat
491
511
  */
492
- static onHeartbeat(callback: (event: HeartbeatEvent) => void): void;
512
+ static onHeartbeat(callback: (event: HeartbeatEvent) => void): Subscription;
493
513
 
494
514
  /**
495
515
  * Subscribe to changes in actively monitored geofences.
@@ -508,7 +528,7 @@ declare module "react-native-background-geolocation" {
508
528
  *
509
529
  * @example
510
530
  * ```typescript
511
- * BackgroundGeolocation.onGeofencesChange((event) => {
531
+ * const subscription = BackgroundGeolocation.onGeofencesChange((event) => {
512
532
  * let on = event.on; //<-- new geofences activated.
513
533
  * let off = event.off; //<-- geofences that were just de-activated.
514
534
  *
@@ -528,7 +548,7 @@ declare module "react-native-background-geolocation" {
528
548
  * - 📘 [[Geofence | Geofencing Guide]]
529
549
  * @event geofenceschange
530
550
  */
531
- static onGeofencesChange(callback: (event: GeofencesChangeEvent) => void): void;
551
+ static onGeofencesChange(callback: (event: GeofencesChangeEvent) => void): Subscription;
532
552
 
533
553
  /**
534
554
  * Subscribe to [[schedule]] events.
@@ -538,7 +558,7 @@ declare module "react-native-background-geolocation" {
538
558
  *
539
559
  * @example
540
560
  * ```typescript
541
- * BackgroundGeolocation.onSchedule((state) => {
561
+ * const subscription = BackgroundGeolocation.onSchedule((state) => {
542
562
  * if (state.enabled) {
543
563
  * console.log("[onSchedule] scheduled start tracking");
544
564
  * } else {
@@ -548,7 +568,7 @@ declare module "react-native-background-geolocation" {
548
568
  * ```
549
569
  * @event schedule
550
570
  */
551
- static onSchedule(callback: (state:State) => void): void;
571
+ static onSchedule(callback: (state:State) => void): Subscription;
552
572
 
553
573
  /**
554
574
  * Subscribe to changes in network connectivity.
@@ -561,13 +581,13 @@ declare module "react-native-background-geolocation" {
561
581
  *
562
582
  * @example
563
583
  * ```typescript
564
- * BackgroundGeolocation.onConnectivityChange((event) => {
584
+ * const subscription = BackgroundGeolocation.onConnectivityChange((event) => {
565
585
  * console.log("[onConnectivityChange] ", event);
566
586
  * });
567
587
  * ```
568
588
  * @event connectivitychange
569
589
  */
570
- static onConnectivityChange(callback: (event:ConnectivityChangeEvent) => void): void;
590
+ static onConnectivityChange(callback: (event:ConnectivityChangeEvent) => void): Subscription;
571
591
 
572
592
  /**
573
593
  * Subscribe to state changes in OS power-saving system.
@@ -592,13 +612,13 @@ declare module "react-native-background-geolocation" {
592
612
  *
593
613
  * @example
594
614
  * ```typescript
595
- * BackgroundGeolocation.onPowerSaveChange((isPowerSaveMode) => {
615
+ * const subscription = BackgroundGeolocation.onPowerSaveChange((isPowerSaveMode) => {
596
616
  * console.log("[onPowerSaveChange: ", isPowerSaveMode);
597
617
  * });
598
618
  * ```
599
619
  * @event powersavechange
600
620
  */
601
- static onPowerSaveChange(callback: (enabled:boolean) => void): void;
621
+ static onPowerSaveChange(callback: (enabled:boolean) => void): Subscription;
602
622
 
603
623
  /**
604
624
  * Subscribe to changes in plugin [[State.enabled]].
@@ -609,18 +629,18 @@ declare module "react-native-background-geolocation" {
609
629
  *
610
630
  * @example
611
631
  * ```typescript
612
- * BackgroundGeolocation.onEnabledChange(isEnabled => {
632
+ * const subscription = BackgroundGeolocation.onEnabledChange(isEnabled => {
613
633
  * console.log("[onEnabledChanged] isEnabled? ", isEnabled);
614
634
  * });
615
635
  * ```
616
636
  * @event enabledchange
617
637
  */
618
- static onEnabledChange(callback: (enabled:boolean) => void): void;
638
+ static onEnabledChange(callback: (enabled:boolean) => void): Subscription;
619
639
 
620
640
  /**
621
641
  * [__Android-only__] Subscribe to button-clicks of a custom [[Notification.layout]] on the Android foreground-service notification.
622
642
  */
623
- static onNotificationAction(callback: (buttonId:string) => void): void;
643
+ static onNotificationAction(callback: (buttonId:string) => void): Subscription;
624
644
 
625
645
  /**
626
646
  * Subscribe to [[Authorization]] events.
@@ -632,7 +652,7 @@ declare module "react-native-background-geolocation" {
632
652
  *
633
653
  * @example
634
654
  * ```typescript
635
- * BackgroundGeolocation.onAuthorization((event) => {
655
+ * const subscription = BackgroundGeolocation.onAuthorization((event) => {
636
656
  * if (event.success) {
637
657
  * console.log("[authorization] ERROR: ", event.error);
638
658
  * } else {
@@ -642,7 +662,7 @@ declare module "react-native-background-geolocation" {
642
662
  * ```
643
663
  *
644
664
  */
645
- static onAuthorization(callback: (event:AuthorizationEvent) => void): void;
665
+ static onAuthorization(callback: (event:AuthorizationEvent) => void): Subscription;
646
666
 
647
667
  /**
648
668
  * Registers a Javascript callback to execute in the Android "Headless" state, where the app has been terminated configured with
@@ -656,7 +676,7 @@ declare module "react-native-background-geolocation" {
656
676
  *
657
677
  * @example
658
678
  * ```typescript
659
- * let BackgroundGeolocationHeadlessTask = async (event) => {
679
+ * const BackgroundGeolocationHeadlessTask = async (event) => {
660
680
  * let params = event.params;
661
681
  * console.log("[BackgroundGeolocation HeadlessTask] -", event.name, params);
662
682
  *
@@ -0,0 +1,104 @@
1
+ declare module "react-native-background-geolocation" {
2
+ /**
3
+ * Object returned by BackgroundGeolocation event-listeners. `Subscription` contains just a single method [[remove]], used for removing an event-listener.
4
+ *
5
+ * - [[BackgroundGeolocation.onLocation]]
6
+ * - [[BackgroundGeolocation.onMotionChange]]
7
+ * - [[BackgroundGeolocation.onHttp]]
8
+ * - [[BackgroundGeolocation.onHeartbeat]]
9
+ * - [[BackgroundGeolocation.onProviderChange]]
10
+ * - [[BackgroundGeolocation.onActivityChange]]
11
+ * - [[BackgroundGeolocation.onGeofence]]
12
+ * - [[BackgroundGeolocation.onGeofencesChange]]
13
+ * - [[BackgroundGeolocation.onEnabledChange]]
14
+ * - [[BackgroundGeolocation.onConnectivityChange]]
15
+ * - [[BackgroundGeolocation.onSchedule]]
16
+ * - [[BackgroundGeolocation.onPowerSaveChange]]
17
+ * - [[BackgroundGeolocation.onNotificationAction]]
18
+ * - [[BackgroundGeolocation.onAuthorization]]
19
+ *
20
+ * In the past, one would remove event-listeners using the __now-deprectated__ [[BackgroundGeolocation.removeListener]].
21
+ *
22
+ * ## Removing an event-listener:
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Event-listeners return a Subscription instance, containing a .remove() method.
27
+ * const subscription = BackgroundGeolocation.onLocation(location => {
28
+ * console.log("[onLocation] ", location);
29
+ * });
30
+ * .
31
+ * .
32
+ * .
33
+ * // Later, to remove the event-listener:
34
+ * subscription.remove();
35
+ * ```
36
+ *
37
+ * One might typically manage a collection of `Subscription` instances
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * import BackgroundGeolocation, {
42
+ * Location,
43
+ * Subscription
44
+ * } from ...
45
+ *
46
+ * // Your custom Collection of Subscription instances.
47
+ * const SUBSCRIPTIONS = [];
48
+ *
49
+ * // Your custom method to push a Subscription instance.
50
+ * const subscribe = (subscription:Subscription) => {
51
+ * SUBSCRIPTIONS.push(subscription);
52
+ * }
53
+ *
54
+ * // Your custom method to interate your SUBSCRIPTIONS and .remove each.
55
+ * const unsubscribe = () => {
56
+ * SUBSCRIPTIONS.forEach((subscription:Subscription) => subscription.remove());
57
+ * }
58
+ *
59
+ * const initBackgroundGeolocation = () {
60
+ * // Create event-listeners as usual, feeding the returned Subscription into
61
+ * // your custom subscribe() method.
62
+ * subscribe(BackgroundGeolocation.onLocation((location:Location) => {
63
+ * console.log('[onLocation]', location);
64
+ * });
65
+ *
66
+ * subscribe(BackgroundGeolocation.onMotionChange((location:Location) => {
67
+ * console.log('[onMotionChange]', location);
68
+ * });
69
+ *
70
+ * subscribe(BackgroundGeolocation.onEnabledChange((enabled:boolean) => {
71
+ * console.log('[onEnabledChange]', enabled);
72
+ * });
73
+ * }
74
+ *
75
+ * const onDestroyView = () => {
76
+ * // Call your custom unsubscribe method
77
+ * unsubscribe();
78
+ * }
79
+ *
80
+ * ```
81
+ */
82
+ interface Subscription {
83
+ /**
84
+ * Removes a `BackgroundGeolocation` event-listener.
85
+ * @example
86
+ * ```typescript
87
+ * // Event-listeners return a Subscription instance, containing a .remove() method.
88
+ * const onLocationSubscription = BackgroundGeolocation.onLocation(location => {
89
+ * console.log("[onLocation] ", location);
90
+ * });
91
+ *
92
+ * const onGeofenceSubscription = BackgroundGeolocation.onGeofence(event => {
93
+ * console.log("[onGeofence] ", event);
94
+ * });
95
+ * .
96
+ * .
97
+ * .
98
+ * // Later, removing event-listeners.
99
+ * onLocationSubscription.remove();
100
+ * onGeofenceSubscription.remove();
101
+ */
102
+ remove():void;
103
+ }
104
+ }