2

locationServicesEnabled関数を機能させようとしましたが、locationServicesが有効になっているかどうかに関係なく、UIAlertが表示されます。これを正しく機能させるにはどうすればよいですか?

 @synthesize locationServicesEnabled
    -(void)viewDidLoad {
     [super viewDidLoad];

     if(![CLLocationManager locationServicesEnabled]) {
      self.locationManager = [[[CLLocationManager alloc] init] autorelease];
      locationManager.delegate = self;
      locationManager.desiredAccuracy = kCLLocationAccuracyBest;
      [locationManager startUpdatingLocation];
        } else {
            [[[[UIAlertView alloc] initWithTitle:@"Location services." 
                                         message:@"Location services are disabled." 
                                        delegate:nil 
                               cancelButtonTitle:@"OK" 
                               otherButtonTitles:nil] autorelease] show];       
        }
    }

前もって感謝します!

4

1 に答える 1

3

状態が逆になっているようです。現在、「位置情報サービスが有効になっていない場合は、elseアラートの更新を開始してください」と表示されます。

次のように変更ifします。

if([CLLocationManager locationServicesEnabled])

を削除し!ます。

于 2010-12-27T16:34:39.853 に答える