Commit 3560e27d authored by Chris Scott's avatar Chris Scott

Debugging getCurrentPosition. Adding success callbacks for several other api...

Debugging getCurrentPosition.  Adding success callbacks for several other api methods, such as start, stop, changePace.
parent eb1fa765
......@@ -103,15 +103,15 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
Boolean result = false;
if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) {
if (ACTION_START.equalsIgnoreCase(action)) {
result = true;
this.setEnabled(true);
callbackContext.success();
callbackContext.success(1);
} else if (ACTION_STOP.equalsIgnoreCase(action)) {
// No implementation to stop background-tasks with Android. Just say "success"
result = true;
this.setEnabled(false);
callbackContext.success();
callbackContext.success(0);
} else if (ACTION_FINISH.equalsIgnoreCase(action)) {
result = true;
callbackContext.success();
......@@ -126,7 +126,7 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} else {
callbackContext.error("- Configuration error!");
}
} else if (ACTION_CHANGE_PACE.equalsIgnoreCase(action)) {
} else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(action)) {
if (!isEnabled) {
Log.w(TAG, "- Cannot change pace while disabled");
result = false;
......@@ -297,6 +297,10 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
}
private void setEnabled(boolean value) {
// Don't set a state that we're already in.
if (value == isEnabled) {
return;
}
isEnabled = value;
Intent launchIntent = this.cordova.getActivity().getIntent();
......@@ -478,9 +482,9 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
} else if (ACTION_RESET_ODOMETER.equalsIgnoreCase(name)) {
PluginResult result = new PluginResult(PluginResult.Status.OK);
resetOdometerCallback.sendPluginResult(result);
} else if (ACTION_CHANGE_PACE.equalsIgnoreCase(name)) {
PluginResult result = new PluginResult(PluginResult.Status.OK);
paceChangeCallback.sendPluginResult(result);
} else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(name)) {
int state = event.getBoolean("isMoving") ? 1 : 0;
paceChangeCallback.success(state);
} else if (ACTION_GET_GEOFENCES.equalsIgnoreCase(name)) {
try {
JSONArray json = new JSONArray(event.getString("data"));
......
......@@ -55,6 +55,9 @@
- (void) start:(CDVInvokedUrlCommand*)command
{
[bgGeo start];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool: true];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
* Turn it off
......@@ -62,6 +65,8 @@
- (void) stop:(CDVInvokedUrlCommand*)command
{
[bgGeo stop];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool: false];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
- (void) getOdometer:(CDVInvokedUrlCommand*)command
{
......@@ -83,6 +88,8 @@
{
BOOL moving = [[command.arguments objectAtIndex: 0] boolValue];
[bgGeo changePace:moving];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool: moving];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
......@@ -307,7 +314,6 @@
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
- (void) onGeofence:(CDVInvokedUrlCommand*)command
{
if (self.geofenceListeners == nil) {
......@@ -318,6 +324,13 @@
- (void) getCurrentPosition:(CDVInvokedUrlCommand*)command
{
if (![bgGeo isEnabled]) {
NSLog(@"- CDVBackgroundGeolocation#getCurrentPosition cannot be used when plugin is disabled");
// If plugin isn't enabled, return 401 Unauthorized
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:401];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
return;
}
if (self.currentPositionListeners == nil) {
self.currentPositionListeners = [[NSMutableArray alloc] init];
}
......@@ -350,7 +363,6 @@
UIBackgroundTaskIdentifier taskId = [[command.arguments objectAtIndex: 0] integerValue];
NSString *error = [command.arguments objectAtIndex:1];
[bgGeo error:taskId message:error];
}
- (void) onLocationManagerError:(NSNotification*)notification
......
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