Commit 270c3042 authored by Chris Scott's avatar Chris Scott

consolidate a bunch of getter methods into one setConfig method

parent 10402f75
...@@ -13,9 +13,7 @@ ...@@ -13,9 +13,7 @@
- (void) stop:(CDVInvokedUrlCommand*)command; - (void) stop:(CDVInvokedUrlCommand*)command;
- (void) finish:(CDVInvokedUrlCommand*)command; - (void) finish:(CDVInvokedUrlCommand*)command;
- (void) onPaceChange:(CDVInvokedUrlCommand*)command; - (void) onPaceChange:(CDVInvokedUrlCommand*)command;
- (void) setStationaryRadius:(CDVInvokedUrlCommand*)command; - (void) setConfig:(CDVInvokedUrlCommand*)command;
- (void) setDesiredAccuracy:(CDVInvokedUrlCommand*)command;
- (void) setDistanceFilter:(CDVInvokedUrlCommand*)command;
- (void) sync:(CLLocation*)location; - (void) sync:(CLLocation*)location;
- (void) onSuspend:(NSNotification *)notification; - (void) onSuspend:(NSNotification *)notification;
......
...@@ -65,7 +65,6 @@ ...@@ -65,7 +65,6 @@
// Set a movement threshold for new events. // Set a movement threshold for new events.
locationManager.activityType = CLActivityTypeOther; locationManager.activityType = CLActivityTypeOther;
locationManager.pausesLocationUpdatesAutomatically = YES; locationManager.pausesLocationUpdatesAutomatically = YES;
locationManager.distanceFilter = distanceFilter; // meters
myRegion = nil; myRegion = nil;
...@@ -77,6 +76,33 @@ ...@@ -77,6 +76,33 @@
NSLog(@" - locationTimeout: %ld", (long)locationTimeout); NSLog(@" - locationTimeout: %ld", (long)locationTimeout);
NSLog(@" - desiredAccuracy: %ld", (long)desiredAccuracy); NSLog(@" - desiredAccuracy: %ld", (long)desiredAccuracy);
} }
- (void) setConfig:(CDVInvokedUrlCommand*)command
{
NSLog(@"- CDVBackgroundGeoLocation setConfig");
NSDictionary *config = [command.arguments objectAtIndex:0];
if (config[@"desiredAccuracy"]) {
desiredAccuracy = [config[@"desiredAccuracy"] intValue];
NSLog(@" desiredAccuracy: %@", config[@"desiredAccuracy"]);
}
if (config[@"stationaryRadius"]) {
stationaryRadius = [config[@"stationaryRadius"] intValue];
NSLog(@" stationaryRadius: %@", config[@"stationaryRadius"]);
}
if (config[@"distanceFilter"]) {
distanceFilter = [config[@"distanceFilter"] intValue];
NSLog(@" distanceFilter: %@", config[@"distanceFilter"]);
}
if (config[@"timeout"]) {
locationTimeout = [config[@"timeout"] intValue];
NSLog(@" locationTimeout: %@", config[@"timeout"]);
}
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/** /**
* Turn on background geolocation * Turn on background geolocation
*/ */
...@@ -116,57 +142,6 @@ ...@@ -116,57 +142,6 @@
[self setPace:isMoving]; [self setPace:isMoving];
} }
} }
/**
* Change stationary radius
*/
- (void) setStationaryRadius:(CDVInvokedUrlCommand *)command
{
stationaryRadius = [[command.arguments objectAtIndex: 0] intValue];
NSLog(@"- CDVBackgroundGeoLocation setStationaryRadius %d", stationaryRadius);
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground) {
[self setPace:isMoving];
}
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
* Change distance-filter
*/
- (void) setDistanceFilter:(CDVInvokedUrlCommand *)command
{
distanceFilter = [[command.arguments objectAtIndex: 0] intValue];
NSLog(@"- CDVBackgroundGeoLocation setDistanceFilter %d", distanceFilter);
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground) {
[self setPace:isMoving];
}
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
* Change stationary radius
*/
- (void) setDesiredAccuracy:(CDVInvokedUrlCommand *)command
{
desiredAccuracy = [[command.arguments objectAtIndex: 0] intValue];
NSLog(@"- CDVBackgroundGeoLocation setDesiredAccuracy %d", desiredAccuracy);
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground) {
[self setPace:isMoving];
}
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/** /**
* Called by js to signify the end of a background-geolocation event * Called by js to signify the end of a background-geolocation event
*/ */
...@@ -302,6 +277,14 @@ ...@@ -302,6 +277,14 @@
NSLog(@" distanceFilter: %d", distanceFilter); NSLog(@" distanceFilter: %d", distanceFilter);
NSLog(@" stationaryRadius: %d", stationaryRadius); NSLog(@" stationaryRadius: %d", stationaryRadius);
// First turn off all monitoring.
if (myRegion != nil) {
[locationManager stopMonitoringForRegion:myRegion];
myRegion = nil;
}
[locationManager stopMonitoringSignificantLocationChanges];
[locationManager stopUpdatingLocation];
switch (desiredAccuracy) { switch (desiredAccuracy) {
case 1000: case 1000:
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
...@@ -317,16 +300,11 @@ ...@@ -317,16 +300,11 @@
break; break;
} }
if (myRegion != nil) { locationManager.distanceFilter = distanceFilter; // meters
[locationManager stopMonitoringForRegion:myRegion];
myRegion = nil;
}
if (value == YES) { if (value == YES) {
[locationManager stopMonitoringSignificantLocationChanges];
locationManager.distanceFilter = distanceFilter;
[locationManager startUpdatingLocation]; [locationManager startUpdatingLocation];
} else { } else {
[locationManager stopUpdatingLocation];
[self startMonitoringStationaryRegion]; [self startMonitoringStationaryRegion];
[locationManager startMonitoringSignificantLocationChanges]; [locationManager startMonitoringSignificantLocationChanges];
} }
......
...@@ -78,27 +78,6 @@ module.exports = { ...@@ -78,27 +78,6 @@ module.exports = {
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'setConfig', 'setConfig',
[config]); [config]);
},
setStationaryRadius: function(value, success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'setStationaryRadius',
[value]);
},
setDesiredAccuracy: function(value, success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'setDesiredAccuracy',
[value]);
},
setDistanceFilter: function(value, success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'setDistanceFilter',
[value]);
} }
}; };
......
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