4
votes

I am getting the following error while trying to ask permission from the user for location in Xcode 9 Beta. I tried adding "Privacy - Location When In Use Usage Description" and "Privacy - Location Usage Description" description in info.plist but still getting the same error.

This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys with string values explaining to the user how the app uses this data

When i try to add "Privacy - Location Always and When in use usage description" it is automatically getting renamed to "Privacy - Location Usage Description" in info.plist

5
Looks like a bug - Open the info.plist in source view and add the key that wayPaulw11
How are you adding the entries into info.plist?Sivajee Battina
Did you copy the error message correctly? According to developer.apple.com/library/content/qa/qa1937/_index.html there is NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription, but no NSLocationAlwaysAndWhenInUseUsageDescription.Martin R
@Paulw11 yeah looks like a bug. When i added it to plist in source view, error goes away. But now the permission alert displays and disappears in few seconds before even i select one :(yaali
@MartinR Yes i copied it correctly.yaali

5 Answers

3
votes

Add "NSLocationAlwaysAndWhenInUseUsageDescription" instead of "Privacy - Location Always and When in use usage description". In the current beta it won't get renamed to anything but it shows the correct dialog for iOS 11.

1
votes

See https://developer.apple.com/documentation/corelocation/choosing_the_authorization_level_for_location_services/request_always_authorization?language=objc

Basically it says you are required to include the NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUsageDescription 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.

I'm currently using Xcode Version 9.0 beta 5 (9M202q) and it works without issues.

1
votes

Important note: It is

NSLocationAlwaysAndWhenInUseUsageDescription,

not

NSLocationAlwaysAndWhenInUsageDescription.

Apple made a typo in their Request Always Authorization guide (Last visited: September 20, 2017).

1
votes

You need to add NSLocationAlwaysAndWhenInUseUsageDescription inInfo.plist this way

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>App_Name requires user’s location for better user experience.</string>

<key>NSLocationAlwaysUsageDescription</key>
<string>App_Name requires user’s location for better user experience.</string>

<key>NSLocationWhenInUseUsageDescription</key>
<string>App_Name requires user’s location for better user experience.</string>
0
votes

Just a heads up, it's not a typo as Hans suggested, it is correct. The format of the setting is confusing but conforms to something like

"[APIModule][Setting][KeyType]"

So the module the setting is for is the app's "NSLocation" calls, the setting is regarding the "Always and When in Use" setting for user location prefs, and the KeyType is a "Usage Description" therefore the resulting key is

NSLocationAlwaysAndWhenInUseUsageDescription

or separated into the composite terms:

NSLocation AlwaysAndWhenInUse UsageDescription