I am having an issue when requesting location permissions from user when I use iOS11 my info.plist contains
<key>NSLocationWhenInUseUsageDescription</key>
<string>When in use permissions</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>always permissions</string>
<key>NSLocationAlwaysAndWhenInUsageDescription</key>
<string>Always and in usage permissions</string>
I have two maps one for customer and another for employees. For employees I need to know their location even if the app is not running or is backgrounded (they are able to turn it off when signing out) and request permission using
locationManager.requestAlwaysAuthorization()
For customer i only need locations while the app is in use and request the permission using
locationManager.requestWhenInUseAuthorization()
In iOS 11 this only requests permission when in usage and never the always on permission.
In iOS 10 it has the correct behaviour.
The behaviour I want is as follows: When they are a customer (not signed in) it only asks for when in use permission. If they sign in (employee) it request location even when not in use.
If anyone can shed some light on what I am missing / done wrong it would be much appreciated.
Something to note if i remove the permission NSLocationAlwaysUsageDescription
iOS10 and iOS11 have the same issue of not requesting always permission.
A bit more clarification.
I have implemented didChangeAuthorization delegate function and it gets called when a users allow the permission from alert from calling requestWhenInUseAuthorization()
however when I call requestWhenInUseAuthorization()
function on location manager the delegate method is not called it is like it's never receiving that call and no alert dialog is shown to the user.
I figured out the issue by creating a quick stand alone app that only asked for permissions, I was given an error log that stated the keys I was using were wrong.
I had NSLocationAlwaysAndWhenInUsageDescription
instead of NSLocationAlwaysAndWhenInUseUsageDescription
which is odd because from the docs it states that NSLocationAlwaysAndWhenInUsageDescription
should be used. Switching to include the correct key fixed issue and now permissions works as expected for iOS 11 and 10.
Thanks for all the help.