2012-10-22 62 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。

相關問題