locationServicesEnabled in iOS >4.0 always showing UIAlert
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 locationServicesEn开发者_StackOverflow社区abled]) {
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!
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 !
.
精彩评论