Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location Access Request in iOS 11

I am requesting the user location in my app.

locationManager.requestAlwaysAuthorization()

This line of code should return this alert message:

enter image description here

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.

enter image description here

like image 695
mahdi Avatar asked Oct 03 '17 13:10

mahdi


2 Answers

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 and NSLocationAlwaysAndWhenInUseUsageDescription keys in your app's Info.plist file. (If your app supports iOS 10 and earlier, the NSLocationAlwaysUsageDescription key is also required.) If those keys are not present, authorization requests fail immediately.

Reference: What's New in Location Technologies Video Session.

like image 172
Ahmad F Avatar answered Oct 25 '22 05:10

Ahmad F


According to WWDC 2017 Session 713 about updates in Location technologies, you should always include When In Use description when linking against iOS 11 and later, if you want to request Always authorization. And iOS will additionally display an option to use location for When-In-Use mode.

Quote from session transcript.

So for iOS 11 we're asking all developers with Always requesting apps to additionally support the WhenInUse authorization mode. This change is both retroactive and forward-looking, so when the user updates to iOS 11, they will be able to authorize any app that requests Always authorization the WhenInUse authorization mode instead. If you link against the iOS 11 SDK, you must provide a WhenInUseUsageDescription. Otherwise, your app will be unable to request Always authorization. Furthermore, when your app requests Always authorization, we will additionally display an option to grant your app WhenInUse authorization instead. With these new three option prompts we have a new UsageDescription string as well. Your app needs to provide an AlwaysAndWhenInUse UsageDescription. Since this is a different key your app must provide it when you link against the new iOS 11 SDK. For apps linked against iOS 11 and later, Core Location will not use the old NSLocationAlways UsageDescription key.

like image 22
Jack Oborin Avatar answered Oct 25 '22 07:10

Jack Oborin