Commit a3a05e74 authored by Chris Scott's avatar Chris Scott

Add an error switch in didFail handler. Don't stop updating location for...

Add an error switch in didFail handler.  Don't stop updating location for code: 0.  This allows user to lose connection briefly, driving through tunnels, entering subway, buildings
parent ab3c2fad
...@@ -256,7 +256,6 @@ ...@@ -256,7 +256,6 @@
if (isDebugging) { if (isDebugging) {
AudioServicesPlaySystemSound (isMoving ? paceChangeYesSound : paceChangeNoSound); AudioServicesPlaySystemSound (isMoving ? paceChangeYesSound : paceChangeNoSound);
[self notify:[NSString stringWithFormat:@"Pace change: %hhd", isMoving]];
} }
if (isMoving) { if (isMoving) {
isAcquiringSpeed = YES; isAcquiringSpeed = YES;
...@@ -347,7 +346,7 @@ ...@@ -347,7 +346,7 @@
// Perhaps our GPS signal was interupted, re-acquire a stationaryLocation now. // Perhaps our GPS signal was interupted, re-acquire a stationaryLocation now.
[self setPace: NO]; [self setPace: NO];
} }
// test the age of the location measurement to determine if the measurement is cached // test the age of the location measurement to determine if the measurement is cached
// in most cases you will not want to rely on cached measurements // in most cases you will not want to rely on cached measurements
NSTimeInterval locationAge = -[location.timestamp timeIntervalSinceNow]; NSTimeInterval locationAge = -[location.timestamp timeIntervalSinceNow];
...@@ -463,7 +462,7 @@ ...@@ -463,7 +462,7 @@
(int) locationManager.distanceFilter]]; (int) locationManager.distanceFilter]];
AudioServicesPlaySystemSound (locationSyncSound); AudioServicesPlaySystemSound (locationSyncSound);
} }
NSMutableDictionary* returnInfo = [NSMutableDictionary dictionaryWithCapacity:8]; NSMutableDictionary* returnInfo = [NSMutableDictionary dictionaryWithCapacity:8];
NSNumber* timestamp = [NSNumber numberWithDouble:([location.timestamp timeIntervalSince1970] * 1000)]; NSNumber* timestamp = [NSNumber numberWithDouble:([location.timestamp timeIntervalSince1970] * 1000)];
[returnInfo setObject:timestamp forKey:@"timestamp"]; [returnInfo setObject:timestamp forKey:@"timestamp"];
...@@ -564,7 +563,22 @@ ...@@ -564,7 +563,22 @@
AudioServicesPlaySystemSound (locationError); AudioServicesPlaySystemSound (locationError);
[self notify:[NSString stringWithFormat:@"Location error: %@", error.localizedDescription]]; [self notify:[NSString stringWithFormat:@"Location error: %@", error.localizedDescription]];
} }
[self stopUpdatingLocation]; switch(error.code) {
case kCLErrorLocationUnknown:
case kCLErrorNetwork:
case kCLErrorRegionMonitoringDenied:
case kCLErrorRegionMonitoringSetupDelayed:
case kCLErrorRegionMonitoringResponseDelayed:
case kCLErrorGeocodeFoundNoResult:
case kCLErrorGeocodeFoundPartialResult:
case kCLErrorGeocodeCanceled:
break;
case kCLErrorDenied:
[self stopUpdatingLocation];
break;
default:
[self stopUpdatingLocation];
}
} }
- (void) stopUpdatingLocation - (void) stopUpdatingLocation
{ {
...@@ -573,6 +587,7 @@ ...@@ -573,6 +587,7 @@
} }
- (void) startUpdatingLocation - (void) startUpdatingLocation
{ {
locationManager.pausesLocationUpdatesAutomatically = YES;
[locationManager startUpdatingLocation]; [locationManager startUpdatingLocation];
isUpdatingLocation = YES; isUpdatingLocation = YES;
} }
...@@ -591,10 +606,10 @@ ...@@ -591,10 +606,10 @@
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
} }
/** /**
* If you don't stopMonitoring when application terminates, the app will be awoken still when a * If you don't stopMonitoring when application terminates, the app will be awoken still when a
* new location arrives, essentially monitoring the user's location even when they've killed the app. * new location arrives, essentially monitoring the user's location even when they've killed the app.
* Might be desirable in certain apps. * Might be desirable in certain apps.
*/ */
- (void)applicationWillTerminate:(UIApplication *)application { - (void)applicationWillTerminate:(UIApplication *)application {
[locationManager stopMonitoringSignificantLocationChanges]; [locationManager stopMonitoringSignificantLocationChanges];
[locationManager stopUpdatingLocation]; [locationManager stopUpdatingLocation];
......
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