简体   繁体   English

NSPhotoLibraryAddUsageDescription和NSPhotoLibraryUsageDescription有什么区别?

[英]What's difference between NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription?

My app get crashed today while updating on Xcode9, testing on iOS11. 我的应用程序今天在Xcode9上进行更新时崩溃,在iOS11上进行测试。 After adding NSPhotoLibraryAddUsageDescription then it works, even i already had NSPhotoLibraryUsageDescription . 添加NSPhotoLibraryAddUsageDescription之后它就可以工作了,即使我已经有了NSPhotoLibraryUsageDescription

Ive read about them, one supported since iOS6, one iOS11 but Apple didn't mention what's difference between them. 我读过他们,一个支持自iOS6,一个iOS11,但Apple没有提到他们之间的区别。 https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW73 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? 如果我保留新的( NSPhotoLibraryAddUsageDescription ),它是否适用于iOS 8,或者我必须保留它们?

Simple get from Apple Official Document 简单来自Apple官方文档

Just click on above image for ZOOM and read it. 只需点击上面的图像即可获得ZOOM并阅读。

For more information on: 有关的更多信息:

As I can see in the document, the difference between two is: 正如我在文档中看到的,两者之间的区别是:

  • NSPhotoLibraryAddUsageDescription: You have permission to write only, no read. NSPhotoLibraryAddUsageDescription:您只能写入,不能读取。

  • NSPhotoLibraryUsageDescription: You can both read and write to Photos. NSPhotoLibraryUsageDescription:您可以读取和写入照片。

From Apple documentations for NSPhotoLibraryUsageDescription: 来自NSPhotoLibraryUsageDescription的Apple文档:

"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. " “虽然这些密钥管理对用户照片库的读写访问权限, 但如果您的应用只需要向资源库添加资产而不需要读取任何资产则最好使用NSPhotoLibraryAddUsageDescription。

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. 您需要声明NSPhotoLibraryUsageDescriptionNSPhotoLibraryAddUsageDescription才能在iOS NSPhotoLibraryUsageDescriptionNSPhotoLibraryAddUsageDescription上使其工作。

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. 我曾经没有声明NSPhotoLibraryUsageDescription ,它在iOS 9和11上工作正常,但在iOS 10.3上失败并崩溃。

This is a really bad version controlling from Apple while higher version doesn't comply and support older version permission. 这是一个非常糟糕的版本控制Apple,而更高版本不符合并支持旧版本权限。

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 . 因为一旦我尝试使用UIActivityViewController将图像保存到库中,我的iphone版本是11.3,我只使用NSPhotoLibraryUsageDescription并且因为我需要NSPhotoLibraryAddUsageDescription崩溃。
But ios 9.3 not crash. 但ios 9.3没有崩溃。

There is a difference for write access based on the API asking for permission as well as the iOS version, so you need both. 基于请求权限的API以及iOS版本的写访问存在差异,因此您需要两者。

My app already had NSPhotoLibraryUsageDescription in order to use PHPhotoLibrary to save images. 我的应用已经有NSPhotoLibraryUsageDescription,以便使用PHPhotoLibrary来保存图像。

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. 在iOS 11上,它仍然有效,但如果我的应用程序尚未获得权限,则通过UIDocumentInteractionController中的“保存图像”共享图像会导致崩溃,并显示有关NSPhotoLibraryAddUsageDescription的警告。 If permission has already been granted via PHPhotoLibrary I don't seem to need NSPhotoLibraryAddUsageDescription for "Save Image". 如果已经通过PHPhotoLibrary授予了权限,我似乎不需要NSPhotoLibraryAddUsageDescription来“保存图像”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM