I am trying to fetch user's location using CLLocationManager
. Here is my simple code:
if(IS_OS_8_OR_LATER) {
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
// iOS8+
// Sending a message to avoid compile time error
[[UIApplication sharedApplication] sendAction:@selector(requestWhenInUseAuthorization)
to:self.locationManager
from:self
forEvent:nil];
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
if (authorizationStatus == kCLAuthorizationStatusAuthorized ||
authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
[self.locationManager startUpdatingLocation];
}else{
[self removeIndicatorView];
return;
}
}
}
My issue is, the code keep executing even the alert is on top. I want to stop the execution until user press allow or deny before updating location. How I can do it?
I don't want to use delay or timer.
Use the delegate method locationManager:didChangeAuthorizationStatus: to run your code when the user allows or disallows the location request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With