从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];
}
为什么应用程序不检索数据而不显示警报弹出窗口?
答案 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个案例kCLErrorHeadingFailure
和kCLErrorLocationUnknown
,但通常不需要......