Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

locationManager didFailWithError

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?

like image 752
zebra Avatar asked Apr 16 '10 12:04

zebra


1 Answers

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...

like image 184
Mihir Mehta Avatar answered Oct 22 '22 04:10

Mihir Mehta