12

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?

RedBlueThing
  • 42,006
  • 17
  • 96
  • 122
zebra
  • 435
  • 2
  • 8
  • 20

1 Answers1

37

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

Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
  • mhmmmm ok, i've understand your code, try but still not receiving popup message: i'll view on my screen latitude and longitude cached value and don't see the alert. ONE THING, i've add an mkreversegeocoder istance and now it will fail to retrieve my city (because i've no connettivity on my phone now). Can be usefoul this info? – zebra Apr 16 '10 at 13:34
  • 1
    ps in my consolle i retrieve only this log: 2010-04-16 15:44:56.509 high[797:207] Error Domain=NSURLErrorDomain Code=-1009 UserInfo=0x178410 "no Internet connection" – zebra Apr 16 '10 at 13:46
  • your console suggest that you're having problem with your internet you can try on different device or on simulator or on different wifi network... see if any of these works... that means your application is fine.... – Mihir Mehta Apr 16 '10 at 14:00
  • nono the error i log is correct, is from mkreversegeocoder not for cllocation;d, it's ok, at the moment my phone cannot be connected on internet, but i expect an error alert in getting position. – zebra Apr 16 '10 at 14:03
  • have you write [locationManager startUpdatingLocation]; in viewdidload or anywhere else...? – Mihir Mehta Apr 17 '10 at 04:36
  • put break point here and see what exactly application is doing... because in any case default alert view should be pop up – Mihir Mehta Apr 20 '10 at 08:37
  • 1
    i get the error in unknown network error in my iPod, How to fix this – SampathKumar Nov 08 '12 at 07:36