zeb*_*bra 12 iphone uialertview iphone-sdk-3.0 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];
}
Run Code Online (Sandbox Code Playgroud)
为什么应用程序不检索数据,并没有显示警报弹出窗口?
Mih*_*hta 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
还有2个案例kCLErrorHeadingFailure ,kCLErrorLocationUnknown但通常不需要......
| 归档时间: |
|
| 查看次数: |
17301 次 |
| 最近记录: |