Pergunta

I try do get the locationServicesEnabled function to work... but my UIAlert shows up no matter if the locationServices is enabled or not! How do I get this to work properly?

 @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];       
        }
    }

Thank you in advance!

Foi útil?

Solução

Looks like your condition is backwards. It currently says "if NOT location-services-enabled then start updating else alert".

Change the if to:

if([CLLocationManager locationServicesEnabled])

Remove the !.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top