locationManager didFailWithError

时间:2010-04-16 12:44:58

标签: iphone iphone-sdk-3.0 uialertview cllocationmanager didfailwitherror

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

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

为什么应用程序不检索数据而不显示警报弹出窗口?

1 个答案:

答案 0 :(得分: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,但通常不需要......