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 @@
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
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];
// Handle location updates as normal, code omitted for brevity.
......@@ -267,9 +270,6 @@
if (isDebugging) {
AudioServicesPlaySystemSound (acquiredLocationSound);
}
[locationManager stopUpdatingLocation];
isAcquiringStationaryLocation = NO;
[locationManager startMonitoringSignificantLocationChanges];
[self startMonitoringStationaryRegion:stationaryLocation];
}
......@@ -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 {
stationaryLocationAttempts++;
if (stationaryLocationAttempts == 4) {
......@@ -391,7 +402,6 @@
{
NSLog(@"- CDVBackgroundGeoLocation paused location updates");
[self setPace:NO];
[self startMonitoringStationaryRegion:[locationManager location]];
}
/**
* 1. Turn off significantChanges ApI
......@@ -413,7 +423,7 @@
if (isDebugging) {
AudioServicesPlaySystemSound (isMoving ? paceChangeYesSound : paceChangeNoSound);
}
if (value == YES) {
if (isMoving) {
if (stationaryRegion != nil) {
[locationManager stopMonitoringForRegion:stationaryRegion];
stationaryRegion = nil;
......@@ -439,9 +449,17 @@
CLLocationCoordinate2D coord = [location coordinate];
NSLog(@"- CDVBackgroundGeoLocation createStationaryRegion (%f,%f)", coord.latitude, coord.longitude);
if (stationaryRegion != nil) {
[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.notifyOnExit = YES;
[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