从一周开始,如果我的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];
} 为什么应用程序不检索数据,也不向我显示警报弹出窗口?
发布于 2010-04-16 21:03:34
因为您只检查了一个条件切换用例,所以需要实现如下所示
- (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个案例是kCLErrorHeadingFailure和kCLErrorLocationUnknown,但通常不需要……
https://stackoverflow.com/questions/2652988
复制相似问题