2

私の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が常に有効になっているという事実でしょうか? 他に何がありますか?

ありがとう

4

1 に答える 1

0

機内モードをオンにすると (Wi-Fi がオフになっていることを確認します)、デバイスで同様の動作が見られます。私の推測では、これは SDK のバグなので、Apple に報告することをお勧めします! さらに調査を行い、わからない場合はバグを報告する予定です。

于 2012-12-07T22:17:34.107 に答える