NSPhotoLibraryAddUsageDescription 和 NSPhotoLibraryUsageDescription 有什么区别?

What's difference between NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription?

我的应用程序今天在 Xcode9 更新时崩溃,在 iOS11 测试。 添加 NSPhotoLibraryAddUsageDescription 之后就可以了,即使我已经有 NSPhotoLibraryUsageDescription.

我读过它们,一个自 iOS6 起支持,一个 iOS11 但 Apple 没有提及它们之间的区别。 https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW73

如果我保留新的 (NSPhotoLibraryAddUsageDescription),它是否也适用于 iOS 8 还是我必须同时保留它们?

Simple get from Apple Official Document

只需点击上图放大阅读即可。

更多信息:

正如我在文档中看到的,两者之间的区别是:

  • NSPhotoLibraryAddUsageDescription: 您有权限只写,没有读。

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

两者你都需要。
因为一旦我尝试使用 UIActivityViewController 将图像保存到库中,我的 iphone 版本是 11.3,我只使用 NSPhotoLibraryUsageDescription 但它崩溃了,因为我需要 NSPhotoLibraryAddUsageDescription .
但是ios 9.3 没有崩溃。

最后一个问题自己回答:

您需要声明 NSPhotoLibraryUsageDescriptionNSPhotoLibraryAddUsageDescription 才能在 iOS 9、10.3 和 11 上运行。

技术上是不同的。 我以前没有声明 NSPhotoLibraryUsageDescription,它在 iOS 9 和 11 上运行良好,但在 iOS 10.3.

上失败并崩溃

这是一个由 Apple 控制的非常糟糕的版本,而更高版本不符合并支持旧版本许可。

基于 API 请求权限和 iOS 版本的写入权限有所不同,因此您需要两者。

我的应用已经有 NSPhotoLibraryUsageDescription 以便使用 PHPhotoLibrary 保存图像。

在 iOS 11 上,这仍然有效,但如果我的应用尚未获得许可,则在 UIDocumentInteractionController 中通过 "Save Image" 共享图像会导致崩溃并显示有关 NSPhotoLibraryAddUsageDescription 的警告。如果已经通过 PHPhotoLibrary 授予权限,我似乎不需要 "Save Image".

的 NSPhotoLibraryAddUsageDescription