38

My app get crashed today while updating on Xcode9, testing on iOS11. After adding NSPhotoLibraryAddUsageDescription then it works, even i already had NSPhotoLibraryUsageDescription.

Ive read about them, one supported since iOS6, one iOS11 but Apple didn't mention what's difference between them. https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW73

If i keep the new one (NSPhotoLibraryAddUsageDescription), will it work for iOS 8 also or i have to keep both of them?

TomSawyer
  • 3,711
  • 6
  • 44
  • 79

5 Answers5

37

Simple get from Apple Official Document

Just click on above image for ZOOM and read it.

For more information on:

Gianfranco P.
  • 10,049
  • 6
  • 51
  • 68
Govaadiyo
  • 5,644
  • 9
  • 43
  • 72
  • 5
    I've read it, it didn't tell anything, please answer my questions above. Both give read and write access, what's diffrence between them, which one should i keep for get both ios version supporting – TomSawyer Sep 21 '17 at 12:45
  • Did you see my screenshot ? If you want to add photo/image in library then you must need to add **NSPhotoLibraryAddUsageDescription** in your **info.plist** – Govaadiyo Sep 21 '17 at 12:46
  • 2
    `NSPhotoLibraryUsageDescription` can do it too, since iOS 6. `Although this keys governs read and write access to the user’s photo library,` – TomSawyer Sep 21 '17 at 12:47
  • That official Doc really helped. Thanks – Akash Neeli Aug 24 '23 at 04:33
15

As I can see in the document, the difference between two is:

  • NSPhotoLibraryAddUsageDescription: You have permission to write only, no read.

  • NSPhotoLibraryUsageDescription: You can both read and write to Photos.

From Apple documentations for NSPhotoLibraryUsageDescription:

"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."

Tien
  • 2,105
  • 17
  • 14
  • 4
    It's unclear how to trigger the dialog for `NSPhotoLibraryAddUsageDescription` - however its definitely crashing apps without it. – dmorrow Sep 26 '17 at 13:57
  • Could you try to call UIImageWriteToSavedPhotosAlbum ? – Tien Sep 26 '17 at 17:56
  • Using `PHPhotoLibrary.requestAuthorization()` seems to work - just not clear which key is being used. – dmorrow Sep 26 '17 at 18:00
  • 2
    PHPhotoLibrary.requestAuthorization() will ask you for NSPhotoLibraryUsageDescription. If you deny on that dialog and you call UIImageWriteToSavedPhotosAlbum, dialog for NSPhotoLibraryAddUsageDescription will appear. – Tien Sep 26 '17 at 18:19
  • 2
    Then what method do you call to check that it is safe to call `UIImageWriteToSavedPhotosAlbum`? – dmorrow Sep 26 '17 at 18:22
9

To answer the last question on my own:

You need to declare both NSPhotoLibraryUsageDescription and NSPhotoLibraryAddUsageDescription to get it WORKS on both iOS 9, 10.3 and 11.

Technically it's different. I used to not declare NSPhotoLibraryUsageDescription, it works fine on iOS 9 and 11 but failed and crashed on iOS 10.3.

This is a really bad version controlling from Apple while higher version doesn't comply and support older version permission.

TomSawyer
  • 3,711
  • 6
  • 44
  • 79
2

You gonna need both.
Because once I tried use UIActivityViewController to save image to library, my iphone version is 11.3, I only use NSPhotoLibraryUsageDescription and it's crash because i need NSPhotoLibraryAddUsageDescription.
But ios 9.3 not crash.

  • 1
    Did you find out to monitor the permission for NSPhotoLibraryAddUsageDescription? Seems like it only return results for NSPhotoLibraryUsageDescription – Roi Mulia Nov 25 '18 at 14:05
2

There is a difference for write access based on the API asking for permission as well as the iOS version, so you need both.

My app already had NSPhotoLibraryUsageDescription in order to use PHPhotoLibrary to save images.

On iOS 11, that still works but if my app hasn't yet got permission then sharing an image via "Save Image" in a UIDocumentInteractionController causes a crash with a warning about NSPhotoLibraryAddUsageDescription. If permission has already been granted via PHPhotoLibrary I don't seem to need NSPhotoLibraryAddUsageDescription for "Save Image".

a4o
  • 81
  • 4