What's difference between NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription?

16,342

Solution 1

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.

Solution 2

Simple get from Apple Official Document

Just click on above image for ZOOM and read it.

For more information on:

Solution 3

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

Solution 4

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

Solution 5

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.

Share:
16,342
TomSawyer
Author by

TomSawyer

Updated on July 07, 2022

Comments

  • TomSawyer
    TomSawyer almost 2 years

    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
    TomSawyer almost 7 years
    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
  • Govaadiyo
    Govaadiyo almost 7 years
    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
  • TomSawyer
    TomSawyer almost 7 years
    NSPhotoLibraryUsageDescription can do it too, since iOS 6. Although this keys governs read and write access to the user’s photo library,
  • dmorrow
    dmorrow almost 7 years
    It's unclear how to trigger the dialog for NSPhotoLibraryAddUsageDescription - however its definitely crashing apps without it.
  • Tien
    Tien almost 7 years
    Could you try to call UIImageWriteToSavedPhotosAlbum ?
  • dmorrow
    dmorrow almost 7 years
    Using PHPhotoLibrary.requestAuthorization() seems to work - just not clear which key is being used.
  • Tien
    Tien almost 7 years
    PHPhotoLibrary.requestAuthorization() will ask you for NSPhotoLibraryUsageDescription. If you deny on that dialog and you call UIImageWriteToSavedPhotosAlbum, dialog for NSPhotoLibraryAddUsageDescription will appear.
  • dmorrow
    dmorrow almost 7 years
    Then what method do you call to check that it is safe to call UIImageWriteToSavedPhotosAlbum?
  • Roi Mulia
    Roi Mulia over 5 years
    Did you find out to monitor the permission for NSPhotoLibraryAddUsageDescription? Seems like it only return results for NSPhotoLibraryUsageDescription