12

从 1 周开始,如果我的 gps 应用程序无法检索信号(例如:在我家进行测试),我不会收到任何警报。我已经以这种方式设置了我的错误通知

- (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]; 
} 

出于什么原因应用程序不检索数据并且不向我显示警报弹出窗口?

4

1 回答 1

37

因为你只检查你需要实现的一个条件开关案例

    - (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;
            }
        }

    }

还有2个案例kCLErrorHeadingFailurekCLErrorLocationUnknown但通常不需要...

于 2010-04-16T13:03:34.063 回答