Skip to content

Commit

Permalink
Allow stopping location updates on status "285 Updates Not Required"
Browse files Browse the repository at this point in the history
  • Loading branch information
mauron85 committed Aug 23, 2018
1 parent 1a3ed1c commit 956d1cf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ function onDeviceReady() {
BackgroundGeolocation.configure({ debug: false });
});

BackgroundGeolocation.on('abort_requested', function() {
console.log('[INFO] Server responded with 285 Updates Not Required');

// Here we can decide whether we want stop the updates or not.
// If you've configured the server to return 285, then it means the server does not require further update.
// So the normal thing to do here would be to `BackgroundGeolocation.stop()`.
// But you might be counting on it to receive location updates in the UI, so you could just reconfigure and set `url` to null.
});

BackgroundGeolocation.checkStatus(function(status) {
console.log('[INFO] BackgroundGeolocation service is running', status.isRunning);
console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
Expand Down Expand Up @@ -444,17 +453,18 @@ Unregister all event listeners for given event

## Events

| Name | Callback param | Platform | Provider* | Description |
|---------------------|------------------------|--------------|-------------|----------------------------------------|
| `location` | `Location` | all | all | on location update |
| `stationary` | `Location` | all | DIS,ACT | on device entered stationary mode |
| `activity` | `Activity` | Android | ACT | on activity detection |
| `error` | `{ code, message }` | all | all | on plugin error |
| `authorization` | `status` | all | all | on user toggle location service |
| `start` | | all | all | geolocation has been started |
| `stop` | | all | all | geolocation has been stopped |
| `foreground` | | Android | all | app entered foreground state (visible) |
| `background` | | Android | all | app entered background state |
| Name | Callback param | Platform | Provider* | Description |
|---------------------|------------------------|--------------|-------------|--------------------------------------------------|
| `location` | `Location` | all | all | on location update |
| `stationary` | `Location` | all | DIS,ACT | on device entered stationary mode |
| `activity` | `Activity` | Android | ACT | on activity detection |
| `error` | `{ code, message }` | all | all | on plugin error |
| `authorization` | `status` | all | all | on user toggle location service |
| `start` | | all | all | geolocation has been started |
| `stop` | | all | all | geolocation has been stopped |
| `foreground` | | Android | all | app entered foreground state (visible) |
| `background` | | Android | all | app entered background state |
| `abort_requested` | | all | all | server responded with "285 Updates Not Required" |

### Location event
| Location parameter | Type | Description |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin implements Plugin
public static final String AUTHORIZATION_EVENT = "authorization";
public static final String START_EVENT = "start";
public static final String STOP_EVENT = "stop";
public static final String ABORT_REQUESTED_EVENT = "abort_requested";

public static final String ACTION_START = "start";
public static final String ACTION_STOP = "stop";
Expand Down Expand Up @@ -564,6 +565,11 @@ public void onServiceStatusChanged(int status) {
}
}

@Override
public void onAbortRequested() {
sendEvent(ABORT_REQUESTED_EVENT, 0);
}

@Override
public void onError(PluginException e) {
sendError(e);
Expand Down
6 changes: 6 additions & 0 deletions ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ -(void) onAppPause:(NSNotification *)notification
[facade switchMode:MAURBackgroundMode];
}

-(void) onAbortRequested
{
NSLog(@"%@ %@", TAG, @"abort requested by the server");
[self sendEvent:@"abort_requested"];
}

/**@
* on UIApplicationDidFinishLaunchingNotification
*/
Expand Down
3 changes: 2 additions & 1 deletion www/BackgroundGeolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var BackgroundGeolocation = {
'error',
'authorization',
'foreground',
'background'
'background',
'abort_requested'
],

DISTANCE_FILTER_PROVIDER: 0,
Expand Down

0 comments on commit 956d1cf

Please sign in to comment.