55

While I have already added:

NSLocationWhenInUseUsageDescription

I keep receiving this warning:

This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSLocationWhenInUseUsageDescription key with a string value explaining to the user how the app uses this data

FYI: I have multiple Info.plist in the app. Not sure what to do.

peterh
  • 11,875
  • 18
  • 85
  • 108
Mohamed
  • 647
  • 1
  • 5
  • 9

5 Answers5

67

Adding both

NSLocationAlwaysAndWhenInUseUsageDescription

and

NSLocationWhenInUseUsageDescription

keys in plist solved my problem.

    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your location is required for xyz benefits for you</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Your location is required for xyz benefits for you</string>
Kartihkraj Duraisamy
  • 3,171
  • 2
  • 25
  • 36
  • I don't understand, why we need to add both keys. The first key's name suggests to me that it should provide the same text for the old keys NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription... – finngu Jul 20 '19 at 13:31
  • 1
    @finngu Not only that, but the [docs](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationwheninuseusagedescription) explicitly state that "If your app needs location information when in the background, use NSLocationAlwaysAndWhenInUseUsageDescription **instead** .". [emphasis mine]. – ispiro Nov 26 '19 at 20:13
31

There are a ton of poorly structured frameworks (namely FirebaseMessaging) that use camera and location for no benefit to the user. You should alert end user this functionality is NOT needed for your application and user must NOT grant app access to that parasite inside. What a sad, sad times we live in.

    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your location is not needed. This request has popped up due to a 3rd party framework used by the app in a context that does NOT need you to reveal you location. Do be sure to check audit trail for the location queries on ios 15 or later.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>You will get zero benefit allowing this app accessing your location. You should never see this alert. If you do alert technical support at foo@bar.baz</string>

Or otherwise do be crafty in the verbiage used to convey the exact usage and risks giving app access to anything outside its sandbox and edufy thy user on the audit trail for the permissions given that has to be examined from time to time (like anyone's gonna do that). Thankfully, lately (circa ios14), Apple reports to the end user suspicious activity such as MapsMe tracking in the background all the time.

Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66
18

Well, actually, in my case I needed to put ALL THREE of them like this:

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>...</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>...</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>...</string>

Otherwise, I wouldn't get the pop-up alert asking to allow the Location. enter image description here

Note: I develop in Flutter, I don't know if it has any repercussions in this case...

Tomas Baran
  • 1,570
  • 2
  • 20
  • 37
5

I was requesting authorisation in

viewDidLoad

as follows:

self.locationManager.requestWhenInUseAuthorization()

when I removed this line the error disappeared.

donjuedo
  • 2,475
  • 18
  • 28
Mohamed
  • 647
  • 1
  • 5
  • 9
  • NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription are for seeking user consent for using their location when you add self.locationManager.requestWhenInUseAuthorization(), it means now you will request for the permission. So If you don't have the use for location, you don't need to add permission strings. And if you do it doesn't matter where you are writing the code to get permission, you should be adding both the permission strings as the answer from @Kartihkraj Duraisamy to get location services working. – pk75 Sep 12 '18 at 05:50
  • I does matter where he is getting permission ;^) Look at a typical app with a dozen of questions waiting for an unsuspecting onboarding user. – Anton Tropashko Sep 11 '20 at 11:22
0

remove the NSLocationWhenInUseUsageDescription from plist and run the application and add again and run the application again

omkar marathe
  • 61
  • 1
  • 7