35
votes

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?

2
why are you are asking question then if you know the answer ? - Varun Naharia
@VarunNaharia because I think it might be useful for anyone facing this crash. meta.stackoverflow.com/questions/314165/… it is legal :) - Ahmad F
There are already same question there you can answer there stackoverflow.com/questions/46566972/… stackoverflow.com/questions/46344159/… - Varun Naharia
@VarunNaharia If I'm not mistaking, these options (as mentioned inhttps://stackguides.com/questions/46341694/detect-add-photos-only-permission question) are unavailable for now... or at least I couldn't find them :) - Ahmad F

2 Answers

81
votes

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

2
votes

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>