locationManager didFailWithError

zebra picture zebra · Apr 16, 2010 · Viewed 17.8k times · Source

from 1 week if my gps app fail to retrieve signal (eg: testing in my home) i don't receive any aler. i've setup my error notification in this way

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {      NSString *errorType = (error.code == kCLErrorDenied) ? 
@"Access Denied" : @"Errore sconosciuto"; 
UIAlertView *alert = [[UIAlertView alloc] 
                      initWithTitle:@"Errore recuperando la Location" 
                      message:errorType 
                      delegate:nil 
                      cancelButtonTitle:@"Okay" 
                      otherButtonTitles:nil]; 
[alert show]; 
[alert release]; 
} 

for what reason app do not retrieve data and do not show me the alert popup?

Answer

Mihir Mehta picture Mihir Mehta · Apr 16, 2010

because you're only checking One condition switch case you need to implement like

    - (void)locationManager: (CLLocationManager *)manager
           didFailWithError: (NSError *)error
    {
        [manager stopUpdatingLocation];
        NSLog(@"error%@",error);
        switch([error code])
        {
            case kCLErrorNetwork: // general, network-related error
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"please check your network connection or that you are not in airplane mode" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                [alert show];
                [alert release];
            }
                    break;
            case kCLErrorDenied:{
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"user has denied to use current Location " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                [alert show];
                [alert release];
            }
                    break;
            default:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"unknown network error" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                [alert show];
                [alert release];
            }
                    break;
            }
        }

    }

There are still 2 more cases kCLErrorHeadingFailure and kCLErrorLocationUnknown but generally it won't be needed...