Commit 797c1a78 authored by Mark Pearce's avatar Mark Pearce

Updated OBJ-C and Java to have new option parameter 'stopOnTerminate'

parent 5e1376a4
......@@ -83,7 +83,8 @@ A full example could be:
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification
activityType: 'AutomotiveNavigation',
debug: true // <-- enable this hear sounds for background-geolocation life-cycle.
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false // <-- enable this to clear background location settings when the app terminates
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
......@@ -181,6 +182,10 @@ Compare now background-geolocation in the scope of a city. In this image, the l
![distanceFilter at city scale](/distance-filter-city.png "distanceFilter at city scale")
#####`@param {Boolean} stopOnTerminate`
Enable this in order to force a stop() when the application terminated (e.g. on iOS, double-tap home button, swipe away the app)
### Android Config
#####`@param {String} url`
......
......@@ -33,6 +33,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private String isDebugging = "false";
private String notificationTitle = "Background tracking";
private String notificationText = "ENABLED";
private String stopOnTerminate = "false";
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
Activity activity = this.cordova.getActivity();
......@@ -56,6 +57,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
updateServiceIntent.putExtra("isDebugging", isDebugging);
updateServiceIntent.putExtra("notificationTitle", notificationTitle);
updateServiceIntent.putExtra("notificationText", notificationText);
updateServiceIntent.putExtra("stopOnTerminate", stopOnTerminate);
activity.startService(updateServiceIntent);
isEnabled = true;
......@@ -69,8 +71,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
result = true;
try {
// Params.
// 0 1 2 3 4 5 6 7 8 8 9
//[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType]
// 0 1 2 3 4 5 6 7 8 8 9 10
//[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType, stopOnTerminate]
this.params = data.getString(0);
this.headers = data.getString(1);
this.url = data.getString(2);
......@@ -81,6 +83,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
this.isDebugging = data.getString(7);
this.notificationTitle = data.getString(8);
this.notificationText = data.getString(9);
this.stopOnTerminate = data.getString(10);
} catch (JSONException e) {
callbackContext.error("authToken/url required as parameters: " + e.getMessage());
}
......@@ -92,4 +95,16 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
return result;
}
/**
* Override method in CordovaPlugin.
* Checks to see if it should turn off
*/
public void onDestroy() {
Activity activity = this.cordova.getActivity();
if(isEnabled && stopOnTerminate.equalsIgnoreCase("true")) {
activity.stopService(updateServiceIntent);
}
}
}
......@@ -94,6 +94,7 @@ public class LocationUpdateService extends Service implements LocationListener {
private Boolean isDebugging;
private String notificationTitle = "Background checking";
private String notificationText = "ENABLED";
private Boolean stopOnTerminate;
private ToneGenerator toneGenerator;
......
......@@ -23,6 +23,7 @@
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command;
- (void) onSuspend:(NSNotification *)notification;
- (void) onResume:(NSNotification *)notification;
- (void) onAppTerminiate:(NSNotification*)notification;
@end
......@@ -21,6 +21,7 @@
BOOL isDebugging;
BOOL enabled;
BOOL isUpdatingLocation;
BOOL stopOnTerminate;
NSString *token;
NSString *url;
......@@ -77,6 +78,7 @@
stationaryLocation = nil;
stationaryRegion = nil;
isDebugging = NO;
stopOnTerminate = NO;
maxStationaryLocationAttempts = 4;
maxSpeedAcquistionAttempts = 3;
......@@ -112,6 +114,7 @@
desiredAccuracy = [self decodeDesiredAccuracy:[[command.arguments objectAtIndex: 6] intValue]];
isDebugging = [[command.arguments objectAtIndex: 7] boolValue];
activityType = [self decodeActivityType:[command.arguments objectAtIndex:9]];
stopOnTerminate = [[command.arguments objectAtIndex: 10] boolValue];
self.syncCallbackId = command.callbackId;
......@@ -129,6 +132,7 @@
NSLog(@" - desiredAccuracy: %ld", (long)desiredAccuracy);
NSLog(@" - activityType: %@", [command.arguments objectAtIndex:7]);
NSLog(@" - debug: %d", isDebugging);
NSLog(@" - stopOnTerminate: %d", stopOnTerminate);
}
- (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command
......@@ -393,6 +397,20 @@
}
}
/**@
* Termination. Checks to see if it should turn off
*/
-(void) onAppTerminiate:(NSNotification *) notification
{
NSLog(@"- CDVBackgroundGeoLocation terminate");
if (isUpdatingLocation && stopOnTerminate) {
[self stopUpdatingLocation];
}
}
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"- CDVBackgroundGeoLocation didUpdateLocations (isMoving: %d)", isMoving);
......
......@@ -22,12 +22,13 @@ module.exports = {
notificationTitle = config.notificationTitle || "Background tracking",
notificationText = config.notificationText || "ENABLED";
activityType = config.activityType || "OTHER";
stopOnTerminate = config.stopOnTerminate || false;
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'configure',
[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType]
[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType, stopOnTerminate]
);
},
start: function(success, failure, config) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment