My app takes the user's location, gets the co-ordinates , and provides a distance to or from their destination or origin. All these possible destinations are shown in a table view, so I'm getting the users co-ordinates at the same time as populating the table. The only thing is, the alert view that asks for the users location appears then disappears so quickly it's impossible to click it!
Is there any way to manually present this alert when the app first loads? I tried getting the user's location when the app loads up to try and force the alert to show, but that didn't work.
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.
Now the location alert disppeared quickly. When I uncomment the last line it is working correctly.
SWIFT 4 @Zoli solution will look like:
you most define locationManager variable as global object.
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 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
fromapplicationWillResignActive
. This was a problem becauseapplicationWillResignActive
is called when the permission dialog appears. This was causingstopUpdatingLocation
immediately afterstartUpdatingLocation
, which is why the dialog would immediately disappear.The solution was simply to call
stopUpdatingLocation
fromapplicationDidEnterBackground
instead.Swift 4 and iOS 11:
Be sure to have added privacy lines (both always and whenInUse) to your
.plist
file and addCoreLocation
Framework to your projectThe location permission dialog appears correctly when I've changed :
with:
P.S.: I've tried ALL advices and all fails (request authorization to
viewDidLoad
,var
instead oflet
for locationManager, don't startstartUpdatingLocation()
after request..I think it's a bug and I hope they will resolve it as soon as possible..