I am requesting the user location in my app.
locationManager.requestAlwaysAuthorization()
This line of code should return this alert message:
However, I want the user to choose between "Don't Allow" and "Always Allow" only. how can I delete the "Only While Using The App" option?
Knowing that this is what I included in the info.plist, and deleting any row from these 3 rows in the info.plist is causing the app not to show this alert at all.
It is not optional anymore.
Since iOS 11 has been released, if your application requests the location to be always on (locationManager.requestAlwaysAuthorization()
), the users will automatically be given all three options.
Unlike in previous iOS versions, all options have to be displayed to the user. That leads to: you have to add a key for both options.
Adapted from Apple's Article - Requesting Always Authorization:
You are required to include the
NSLocationWhenInUseUsageDescription
andNSLocationAlwaysAndWhenInUseUsageDescription
keys in your app's Info.plist file. (If your app supports iOS 10 and earlier, theNSLocationAlwaysUsageDescription
key is also required.) If those keys are not present, authorization requests fail immediately.
Reference: What's New in Location Technologies Video Session.