Not able to add "Privacy - Location Always and When in use usage description" in info.plist - Xcode 9 Beta
Asked Answered
P

5

5

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

Pycnidium answered 11/7, 2017 at 11:42 Comment(12)
Looks like a bug - Open the info.plist in source view and add the key that wayTarazi
How are you adding the entries into info.plist?Cuthbertson
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.Geld
@Tarazi 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 :(Pycnidium
@MartinR Yes i copied it correctly.Pycnidium
@yaali that is typically caused by your CLLocationManager going out of scope; make sure you are holding a reference in a strong propetyTarazi
@Tarazi I am not holding it with weak property. By default in swift i guess it should have strong reference to it. Please correct me if i am wrong. Its strange that the same code works fine in Xcode 8.3.3 but not in Xcode 9 betaPycnidium
Swift properties are strong by default. Can you show your code?Tarazi
@Tarazi Please find the code snippet, var locationManager: CLLocationManager! locationManager = CLLocationManager() locationManager.delegate = self locationManager.requestAlwaysAuthorization() locationManager.allowsBackgroundLocationUpdates = truePycnidium
Hmm. I just tried it and it worked correctly. Perhaps try deleting the app from the device/simulator?Tarazi
Let us continue this discussion in chat.Pycnidium
Try to add this Key in your Plist "Privacy - Location When In Use Usage Description"Amoroso
S
4

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.

Spiccato answered 11/7, 2017 at 13:57 Comment(0)
C
3

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>
Covin answered 6/6, 2019 at 11:39 Comment(1)
NSLocationAlwaysUsageDescription deprecatedPreacher
C
1

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.

Craftwork answered 15/8, 2017 at 22:20 Comment(0)
B
1

Important note: It is

NSLocationAlwaysAndWhenInUseUsageDescription,

not

NSLocationAlwaysAndWhenInUsageDescription.

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

Bellybutton answered 20/9, 2017 at 12:53 Comment(0)
E
0

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

Eggshaped answered 18/2, 2020 at 21:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.