Commit d2cfb3b4 authored by Chris Scott's avatar Chris Scott

Implement locationManager failure-handler for handling airplane-mode, no GPS

parent cdedf302
...@@ -235,7 +235,10 @@ ...@@ -235,7 +235,10 @@
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations -(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{ {
NSLog(@"- CDVBackgroundGeoLocation didUpdateLocations (isMoving: %hhd)", isMoving); NSLog(@"- CDVBackgroundGeoLocation didUpdateLocations (isMoving: %hhd)", isMoving);
if (!isMoving && !isAcquiringStationaryLocation && !stationaryLocation) {
// Perhaps our GPS signal was interupted, re-acquire a stationaryLocation now.
[self setPace: NO];
}
CLLocation *newLocation = [locations lastObject]; CLLocation *newLocation = [locations lastObject];
// Handle location updates as normal, code omitted for brevity. // Handle location updates as normal, code omitted for brevity.
...@@ -267,9 +270,6 @@ ...@@ -267,9 +270,6 @@
if (isDebugging) { if (isDebugging) {
AudioServicesPlaySystemSound (acquiredLocationSound); AudioServicesPlaySystemSound (acquiredLocationSound);
} }
[locationManager stopUpdatingLocation];
isAcquiringStationaryLocation = NO;
[locationManager startMonitoringSignificantLocationChanges];
[self startMonitoringStationaryRegion:stationaryLocation]; [self startMonitoringStationaryRegion:stationaryLocation];
} }
...@@ -306,6 +306,17 @@ ...@@ -306,6 +306,17 @@
} }
} }
} }
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"- CDVBackgroundGeoLocation locationManager failed: %@", error);
[locationManager stopUpdatingLocation];
isMoving = NO;
isAcquiringStationaryLocation = NO;
stationaryLocation = nil;
[locationManager startMonitoringSignificantLocationChanges];
}
-(BOOL) isBestStationaryLocation:(CLLocation*)location { -(BOOL) isBestStationaryLocation:(CLLocation*)location {
stationaryLocationAttempts++; stationaryLocationAttempts++;
if (stationaryLocationAttempts == 4) { if (stationaryLocationAttempts == 4) {
...@@ -391,7 +402,6 @@ ...@@ -391,7 +402,6 @@
{ {
NSLog(@"- CDVBackgroundGeoLocation paused location updates"); NSLog(@"- CDVBackgroundGeoLocation paused location updates");
[self setPace:NO]; [self setPace:NO];
[self startMonitoringStationaryRegion:[locationManager location]];
} }
/** /**
* 1. Turn off significantChanges ApI * 1. Turn off significantChanges ApI
...@@ -413,7 +423,7 @@ ...@@ -413,7 +423,7 @@
if (isDebugging) { if (isDebugging) {
AudioServicesPlaySystemSound (isMoving ? paceChangeYesSound : paceChangeNoSound); AudioServicesPlaySystemSound (isMoving ? paceChangeYesSound : paceChangeNoSound);
} }
if (value == YES) { if (isMoving) {
if (stationaryRegion != nil) { if (stationaryRegion != nil) {
[locationManager stopMonitoringForRegion:stationaryRegion]; [locationManager stopMonitoringForRegion:stationaryRegion];
stationaryRegion = nil; stationaryRegion = nil;
...@@ -439,9 +449,17 @@ ...@@ -439,9 +449,17 @@
CLLocationCoordinate2D coord = [location coordinate]; CLLocationCoordinate2D coord = [location coordinate];
NSLog(@"- CDVBackgroundGeoLocation createStationaryRegion (%f,%f)", coord.latitude, coord.longitude); NSLog(@"- CDVBackgroundGeoLocation createStationaryRegion (%f,%f)", coord.latitude, coord.longitude);
if (stationaryRegion != nil) { if (stationaryRegion != nil) {
[locationManager stopMonitoringForRegion:stationaryRegion]; [locationManager stopMonitoringForRegion:stationaryRegion];
} }
isAcquiringStationaryLocation = NO;
[locationManager stopUpdatingLocation];
locationManager.distanceFilter = distanceFilter;
locationManager.desiredAccuracy = desiredAccuracy;
[locationManager startMonitoringSignificantLocationChanges];
stationaryRegion = [[CLCircularRegion alloc] initWithCenter: coord radius:stationaryRadius identifier:@"BackgroundGeoLocation stationary region"]; stationaryRegion = [[CLCircularRegion alloc] initWithCenter: coord radius:stationaryRadius identifier:@"BackgroundGeoLocation stationary region"];
stationaryRegion.notifyOnExit = YES; stationaryRegion.notifyOnExit = YES;
[locationManager startMonitoringForRegion:stationaryRegion]; [locationManager startMonitoringForRegion:stationaryRegion];
......
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