私のiOSアプリケーションにはマップビューがあり、使用しようとしています
(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" ポップアップが正しく表示されます。一方、PC (iPhone シミュレーターを使用しています) からイーサネット ケーブルが取り外された場合、kCLErrorNetwork エラーは発生しません。
iPhoneシミュレーターでは、インターネット接続がない場合でも、wifiが常に有効になっているという事実でしょうか? 他に何がありますか?
ありがとう