1
在我的iPhone應用程序,我有一個MapView,我嘗試使用爲什麼kCLErrorNetwork不被調用?
(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
方法來查看用戶是否啓用位置服務,同時,如果有互聯網連接。
在我的.m我這樣做:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];
}
return self;
}
這:
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error{
[manager stopUpdatingLocation];
NSLog(@"didFailWithError: %@\n\n\n", error);
switch ([error code]) {
case kCLErrorNetwork:{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"please check your internet connection or that you are not in airplane mode" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
break;
case kCLErrorDenied:{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"enable location services to see your current position." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
break;
default:{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Unknown network error" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
break;
}
}
如果用戶不允許應用程序使用位置服務,他會得到正確的「kCLErrorDenied」彈出。另一方面,如果從我的電腦(我使用iPhone模擬器)的以太網電纜被刪除,我不會得到kCLErrorNetwork錯誤。
難道是在iPhone模擬器上,即使沒有互聯網連接,wifi始終啓用? 它還能做什麼?
感謝
有人可以幫我嗎?任何答案將不勝感激 – puntotuning