40

I faced the following error (iOS 11):

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

Note that although the application info.plist does contains NSPhotoLibraryUsageDescription it still crashes, why?

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
  • why are you are asking question then if you know the answer ? – Varun Naharia Oct 11 '17 at 06:38
  • @VarunNaharia because I think it might be useful for anyone facing this crash. https://meta.stackoverflow.com/questions/314165/how-to-ask-and-self-answer-a-correct-high-quality-qa-pair-without-attracting-d it is legal :) – Ahmad F Oct 11 '17 at 06:46
  • There are already same question there you can answer there https://stackoverflow.com/questions/46566972/request-nsphotolibraryaddusagedescription-permission https://stackoverflow.com/questions/46344159/whats-difference-between-nsphotolibraryaddusagedescription-and-nsphotolibraryus – Varun Naharia Oct 11 '17 at 06:51
  • @VarunNaharia If I'm not mistaking, these options (as mentioned inhttps://stackoverflow.com/questions/46341694/detect-add-photos-only-permission question) are unavailable for now... or at least I couldn't find them :) – Ahmad F Oct 11 '17 at 07:11

2 Answers2

90

Note that although the application info.plist does contains NSPhotoLibraryUsageDescription it still crashes, why?

I think there is a misunderstanding when comparing NSPhotoLibraryUsageDescription and NSPhotoLibraryAddUsageDescription, as documented in Information Property List Key Reference:

NSPhotoLibraryUsageDescription:

This key lets you describe the reason your app accesses the user’s photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.

It is related to letting the app to be able to access (get) the device photos library.

NSPhotoLibraryAddUsageDescription:

This key lets you describe the reason your app seeks write-only access to the user’s photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.

It is related to letting the app to be able to write (add) photos into the device photos library.


Obviously, to solve this crash you have to add the NSPhotoLibraryAddUsageDescription into the application's plist file:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Our application needs permission to write photos...</string>

As property list view:

enter image description here

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
  • 6
    Apple’s documentation for `NSPhotoLibraryUsageDescription` specifically states that it is for both read & write access: "Although this keys governs **read and write access** to the user’s photo library, it’s best to use NSPhotoLibraryAddUsageDescription if your app needs only to add assets to the library and does not need to read any assets.” I don’t know if this is just a bug in the Documentation or if Apple purposefully changed the behavior for `NSPhotoLibraryUsageDescription` to be read-only. – Cutterpillow Nov 09 '17 at 00:21
  • @Cutterpillow I think your second assumption it correct. – Ahmad F Feb 23 '18 at 19:59
  • If you open iOS settings and navigation to your app you will see *read and write* with *NSPhotoLibraryUsageDescription*. That is why it looks like a bug – iWheelBuy May 23 '18 at 01:52
  • If you want to add photos to the library you need to use the "Privacy - Photo Library Additions Usage Description" key. I used both that key and the "Privacy - Photo Library Usage Description" keys and things worked properly. – David Jarrin Feb 27 '20 at 10:25
  • Hi, still the same issue after a few years. My question is, how I can ask for permission for "NSPhotoLibraryAddUsageDescription"? Or I just need to add Key, String to my plist file? @AhmadF – A. Amini Sep 04 '20 at 09:17
  • @A.Amini you have to add it into the plist. – Ahmad F Sep 06 '20 at 16:14
2

There is a typo in the above answer. The correct plist entry should be as follows

<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) needs permission to access photos on your device</string>
Arunabh Das
  • 13,212
  • 21
  • 86
  • 109