2012-10-22 60 views
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始终启用? 它还能做什么?

感谢

+0

有人可以帮我吗?任何答案将不胜感激 – puntotuning

回答

0

我在设备上看到类似的行为,如果我打开飞行模式(并确保Wi-Fi已关闭)。我的猜测是,这是一个SDK错误,所以我建议向苹果提交一份!如果我无法弄清楚,我打算进行更多的研究并提交bug。

相关问题