Commit 5c08e446 authored by Chris Scott's avatar Chris Scott

Discovering that aggressive tracking cannot be initiated from a background...

Discovering that aggressive tracking cannot be initiated from a background push.  when started, ensure we always set isMoving: false
parent f6e518fe
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
locationManager.pausesLocationUpdatesAutomatically = YES; locationManager.pausesLocationUpdatesAutomatically = YES;
myRegion = nil; myRegion = nil;
isMoving = NO;
NSLog(@"CDVBackgroundGeoLocation configure"); NSLog(@"CDVBackgroundGeoLocation configure");
NSLog(@" - token: %@", token); NSLog(@" - token: %@", token);
...@@ -119,8 +120,12 @@ ...@@ -119,8 +120,12 @@
NSLog(@"- CDVBackgroundGeoLocation start (background? %d)", state); NSLog(@"- CDVBackgroundGeoLocation start (background? %d)", state);
if (state == UIApplicationStateBackground) { if (state == UIApplicationStateBackground) {
[self setPace:isMoving]; [self setPace:NO];
} }
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} }
/** /**
* Turn it off * Turn it off
...@@ -129,9 +134,18 @@ ...@@ -129,9 +134,18 @@
{ {
NSLog(@"- CDVBackgroundGeoLocation stop"); NSLog(@"- CDVBackgroundGeoLocation stop");
enabled = NO; enabled = NO;
[locationManager stopUpdatingLocation]; [locationManager stopUpdatingLocation];
[locationManager stopMonitoringSignificantLocationChanges]; [locationManager stopMonitoringSignificantLocationChanges];
if (myRegion != nil) {
[locationManager stopMonitoringForRegion:myRegion];
myRegion = nil;
}
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} }
/** /**
* Change pace to moving/stopped * Change pace to moving/stopped
...@@ -245,7 +259,9 @@ ...@@ -245,7 +259,9 @@
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{ {
NSLog(@"- CDVBackgroundGeoLocation exit region"); NSLog(@"- CDVBackgroundGeoLocation exit region");
if (enabled) {
[self setPace:YES]; [self setPace:YES];
}
} }
/** /**
* 1. turn off std location services * 1. turn off std location services
...@@ -274,7 +290,7 @@ ...@@ -274,7 +290,7 @@
- (void)setPace:(BOOL)value - (void)setPace:(BOOL)value
{ {
// When stationaryRadius is 0, don't use sig.changes -- keep GPS on constantly. // When stationaryRadius is 0, don't use sig.changes -- keep GPS on constantly.
isMoving = (stationaryRadius == 0) ? YES : value; isMoving = value;
NSLog(@"- CDVBackgroundGeoLocation setPace"); NSLog(@"- CDVBackgroundGeoLocation setPace");
NSLog(@" isMoving %d", isMoving); NSLog(@" isMoving %d", isMoving);
...@@ -305,13 +321,13 @@ ...@@ -305,13 +321,13 @@
break; break;
} }
locationManager.distanceFilter = distanceFilter; // meters locationManager.distanceFilter = (distanceFilter > 0) ? distanceFilter : kCLDistanceFilterNone;
if (isMoving) { if (isMoving) {
[locationManager startUpdatingLocation]; [locationManager startUpdatingLocation];
} else { } else {
[self startMonitoringStationaryRegion];
[locationManager startMonitoringSignificantLocationChanges]; [locationManager startMonitoringSignificantLocationChanges];
[self startMonitoringStationaryRegion];
} }
} }
/** /**
...@@ -322,7 +338,9 @@ ...@@ -322,7 +338,9 @@
if (myRegion != nil) { if (myRegion != nil) {
[locationManager stopMonitoringForRegion:myRegion]; [locationManager stopMonitoringForRegion:myRegion];
} }
myRegion = [[CLCircularRegion alloc] initWithCenter: [[locationManager location] coordinate] radius:stationaryRadius identifier:@"BackgroundGeoLocation stationary region"]; NSInteger radius = (stationaryRadius>0) ? stationaryRadius : 1;
myRegion = [[CLCircularRegion alloc] initWithCenter: [[locationManager location] coordinate] radius:radius identifier:@"BackgroundGeoLocation stationary region"];
myRegion.notifyOnExit = YES; myRegion.notifyOnExit = YES;
[locationManager startMonitoringForRegion:myRegion]; [locationManager startMonitoringForRegion:myRegion];
} }
......
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