While difficult to track down, the solution for this is quite simple.
Through much trial and error I found out that while the location access dialog pops up when you try to access any location services in the app for the first time, the dialog disappears on its own (without any user interaction) if the CLLocationManager
object is released before the user responds to the dialog.
I was creating a CLLocationManager
instance in my viewDidLoad
method. Since this was a local instance to the method, the instance was released by ARC after the method completed executing. As soon as the instance was released, the dialog disappeared. The solution was rather simple. Change the CLLocationManager
instance from being a method-level variable to be a class-level instance variable. Now the CLLocationManager
instance is only released once the class is unloaded.
Same symptom, different cause: do not to call startUpdatingLocation
more than once in a row.
I had accidentally structured things such that the code was unintentionally calling startUpdatingLocation
twice in a row, which is apparently bad. It might also have had something to do with choice of queue since I was waiting to start updating pending the result of a network request, but I didn't need to do any GCD magic to fix it...just needed to make sure I didn't repeat the start.
Hope someone's able to benefit from my pain. :)
I have faced the similar situation. After debugging I found
let locationManager = CLLocationManager()
is called in a method scope, but it should be called globally.
Why?
In a nutshell, locationManager has been released after the method had returned. But it shouldn't be released until user give or deny permission
I fall into the same issue (at least by symptoms).
In my case the problem was in the - (void)applicationWillResignActive:(UIApplication *)application;
method, where I was releasing my CLLocationManager
instance as part of preparing for background transition. When I removed it and left it only in - (void)applicationDidEnterBackground:(UIApplication *)application;
the problem is gone.
The tricky part is that Core Location alert DO suspend your application while it still in foreground.
Hope that it will help you, took me a lot of time to found that bastard :)
I know this is a very late reply. But it may help someone. I also faced the same problem and spent an hour to identify the issue. At first my code was like this.
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
CLLocation *location = locationManager.location;
//my stuff with the location
[locationManager release];
Now the location alert disppeared quickly. When I uncomment the last line it is working correctly.
// [locationManager release];
I ran into this problem, also, but the solution in my case turned out to be completely different than the accepted answer.
In my app, I was calling stopUpdatingLocation
from applicationWillResignActive
. This was a problem because applicationWillResignActive
is called when the permission dialog appears. This was causing stopUpdatingLocation
immediately after startUpdatingLocation
, which is why the dialog would immediately disappear.
The solution was simply to call stopUpdatingLocation
from applicationDidEnterBackground
instead.
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