![](/img/trans.png)
[英]What is the crash of “The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription”?
[英]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,或者我必須保留它們?
只需點擊上面的圖像即可獲得ZOOM並閱讀。
有關的更多信息:
NSPhotoLibraryAddUsageDescription :如果要將照片/圖像保存到照片庫。 適用於iOS11 and +
NSPhotoLibraryUsageDescription :如果要訪問照片庫。 適用於iOS10 and +
正如我在文檔中看到的,兩者之間的區別是:
NSPhotoLibraryAddUsageDescription:您只能寫入,不能讀取。
NSPhotoLibraryUsageDescription:您可以讀取和寫入照片。
來自NSPhotoLibraryUsageDescription的Apple文檔:
“雖然這些密鑰管理對用戶照片庫的讀寫訪問權限, 但如果您的應用只需要向資源庫添加資產而不需要讀取任何資產 , 則最好使用NSPhotoLibraryAddUsageDescription。 ”
我自己回答最后一個問題:
您需要聲明NSPhotoLibraryUsageDescription
和NSPhotoLibraryAddUsageDescription
才能在iOS NSPhotoLibraryUsageDescription
和NSPhotoLibraryAddUsageDescription
上使其工作。
從技術上講,它是不同的。 我曾經沒有聲明NSPhotoLibraryUsageDescription
,它在iOS 9和11上工作正常,但在iOS 10.3上失敗並崩潰。
這是一個非常糟糕的版本控制Apple,而更高版本不符合並支持舊版本權限。
你需要兩個。
因為一旦我嘗試使用UIActivityViewController
將圖像保存到庫中,我的iphone版本是11.3,我只使用NSPhotoLibraryUsageDescription
並且因為我需要NSPhotoLibraryAddUsageDescription
崩潰。
但ios 9.3沒有崩潰。
基於請求權限的API以及iOS版本的寫訪問存在差異,因此您需要兩者。
我的應用已經有NSPhotoLibraryUsageDescription,以便使用PHPhotoLibrary來保存圖像。
在iOS 11上,它仍然有效,但如果我的應用程序尚未獲得權限,則通過UIDocumentInteractionController中的“保存圖像”共享圖像會導致崩潰,並顯示有關NSPhotoLibraryAddUsageDescription的警告。 如果已經通過PHPhotoLibrary授予了權限,我似乎不需要NSPhotoLibraryAddUsageDescription來“保存圖像”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.