Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's difference between NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription?

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?

like image 588
TomSawyer Avatar asked Sep 21 '17 12:09

TomSawyer


5 Answers

Simple get from Apple Official Document

Just click on above image for ZOOM and read it.

For more information on:

  • NSPhotoLibraryAddUsageDescription: If you want to save a photo/image to your Photo Library. For iOS11 and +

  • NSPhotoLibraryUsageDescription: If you want to access your Photo Library. For iOS10 and +

like image 200
Govaadiyo Avatar answered Oct 17 '22 20:10

Govaadiyo


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

like image 29
Tien Avatar answered Oct 17 '22 20:10

Tien


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.

like image 9
TomSawyer Avatar answered Oct 17 '22 21:10

TomSawyer


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.

like image 2
Linh Quang Pham Avatar answered Oct 17 '22 20:10

Linh Quang Pham


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

like image 2
a4o Avatar answered Oct 17 '22 21:10

a4o