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: ...@@ -83,7 +83,8 @@ A full example could be:
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification notificationText: 'ENABLED', // <-- android only, customize the text of the notification
activityType: 'AutomotiveNavigation', 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. // 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 ...@@ -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") ![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 ### Android Config
#####`@param {String} url` #####`@param {String} url`
......
...@@ -33,6 +33,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -33,6 +33,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private String isDebugging = "false"; private String isDebugging = "false";
private String notificationTitle = "Background tracking"; private String notificationTitle = "Background tracking";
private String notificationText = "ENABLED"; private String notificationText = "ENABLED";
private String stopOnTerminate = "false";
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) { public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
Activity activity = this.cordova.getActivity(); Activity activity = this.cordova.getActivity();
...@@ -56,6 +57,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -56,6 +57,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
updateServiceIntent.putExtra("isDebugging", isDebugging); updateServiceIntent.putExtra("isDebugging", isDebugging);
updateServiceIntent.putExtra("notificationTitle", notificationTitle); updateServiceIntent.putExtra("notificationTitle", notificationTitle);
updateServiceIntent.putExtra("notificationText", notificationText); updateServiceIntent.putExtra("notificationText", notificationText);
updateServiceIntent.putExtra("stopOnTerminate", stopOnTerminate);
activity.startService(updateServiceIntent); activity.startService(updateServiceIntent);
isEnabled = true; isEnabled = true;
...@@ -69,8 +71,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -69,8 +71,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
result = true; result = true;
try { try {
// Params. // Params.
// 0 1 2 3 4 5 6 7 8 8 9 // 0 1 2 3 4 5 6 7 8 8 9 10
//[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType] //[params, headers, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug, notificationTitle, notificationText, activityType, stopOnTerminate]
this.params = data.getString(0); this.params = data.getString(0);
this.headers = data.getString(1); this.headers = data.getString(1);
this.url = data.getString(2); this.url = data.getString(2);
...@@ -81,6 +83,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -81,6 +83,7 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
this.isDebugging = data.getString(7); this.isDebugging = data.getString(7);
this.notificationTitle = data.getString(8); this.notificationTitle = data.getString(8);
this.notificationText = data.getString(9); this.notificationText = data.getString(9);
this.stopOnTerminate = data.getString(10);
} catch (JSONException e) { } catch (JSONException e) {
callbackContext.error("authToken/url required as parameters: " + e.getMessage()); callbackContext.error("authToken/url required as parameters: " + e.getMessage());
} }
...@@ -92,4 +95,16 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -92,4 +95,16 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
return result; 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 { ...@@ -94,6 +94,7 @@ public class LocationUpdateService extends Service implements LocationListener {
private Boolean isDebugging; private Boolean isDebugging;
private String notificationTitle = "Background checking"; private String notificationTitle = "Background checking";
private String notificationText = "ENABLED"; private String notificationText = "ENABLED";
private Boolean stopOnTerminate;
private ToneGenerator toneGenerator; private ToneGenerator toneGenerator;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command; - (void) getStationaryLocation:(CDVInvokedUrlCommand *)command;
- (void) onSuspend:(NSNotification *)notification; - (void) onSuspend:(NSNotification *)notification;
- (void) onResume:(NSNotification *)notification; - (void) onResume:(NSNotification *)notification;
- (void) onAppTerminiate:(NSNotification*)notification;
@end @end
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
BOOL isDebugging; BOOL isDebugging;
BOOL enabled; BOOL enabled;
BOOL isUpdatingLocation; BOOL isUpdatingLocation;
BOOL stopOnTerminate;
NSString *token; NSString *token;
NSString *url; NSString *url;
...@@ -77,6 +78,7 @@ ...@@ -77,6 +78,7 @@
stationaryLocation = nil; stationaryLocation = nil;
stationaryRegion = nil; stationaryRegion = nil;
isDebugging = NO; isDebugging = NO;
stopOnTerminate = NO;
maxStationaryLocationAttempts = 4; maxStationaryLocationAttempts = 4;
maxSpeedAcquistionAttempts = 3; maxSpeedAcquistionAttempts = 3;
...@@ -112,6 +114,7 @@ ...@@ -112,6 +114,7 @@
desiredAccuracy = [self decodeDesiredAccuracy:[[command.arguments objectAtIndex: 6] intValue]]; desiredAccuracy = [self decodeDesiredAccuracy:[[command.arguments objectAtIndex: 6] intValue]];
isDebugging = [[command.arguments objectAtIndex: 7] boolValue]; isDebugging = [[command.arguments objectAtIndex: 7] boolValue];
activityType = [self decodeActivityType:[command.arguments objectAtIndex:9]]; activityType = [self decodeActivityType:[command.arguments objectAtIndex:9]];
stopOnTerminate = [[command.arguments objectAtIndex: 10] boolValue];
self.syncCallbackId = command.callbackId; self.syncCallbackId = command.callbackId;
...@@ -129,6 +132,7 @@ ...@@ -129,6 +132,7 @@
NSLog(@" - desiredAccuracy: %ld", (long)desiredAccuracy); NSLog(@" - desiredAccuracy: %ld", (long)desiredAccuracy);
NSLog(@" - activityType: %@", [command.arguments objectAtIndex:7]); NSLog(@" - activityType: %@", [command.arguments objectAtIndex:7]);
NSLog(@" - debug: %d", isDebugging); NSLog(@" - debug: %d", isDebugging);
NSLog(@" - stopOnTerminate: %d", stopOnTerminate);
} }
- (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command - (void) addStationaryRegionListener:(CDVInvokedUrlCommand*)command
...@@ -393,6 +397,20 @@ ...@@ -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 -(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{ {
NSLog(@"- CDVBackgroundGeoLocation didUpdateLocations (isMoving: %d)", isMoving); NSLog(@"- CDVBackgroundGeoLocation didUpdateLocations (isMoving: %d)", isMoving);
......
...@@ -22,12 +22,13 @@ module.exports = { ...@@ -22,12 +22,13 @@ module.exports = {
notificationTitle = config.notificationTitle || "Background tracking", notificationTitle = config.notificationTitle || "Background tracking",
notificationText = config.notificationText || "ENABLED"; notificationText = config.notificationText || "ENABLED";
activityType = config.activityType || "OTHER"; activityType = config.activityType || "OTHER";
stopOnTerminate = config.stopOnTerminate || false;
exec(success || function() {}, exec(success || function() {},
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'configure', '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) { 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