ios “应用程序的 Info.plist 必须包含 NSPhotoLibraryAddUsageDescription”的崩溃是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46681344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:34:13  来源:igfitidea点击:

What is the crash of "The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription"?

iospermissionsios11

提问by Ahmad F

I faced the following error (iOS 11):

我遇到了以下错误(iOS 11):

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryAddUsageDescriptionkey with a string value explaining to the user how the app uses this data.

此应用程序已崩溃,因为它试图在没有使用说明的情况下访问隐私敏感数据。应用程序的 Info.plist 必须包含一个NSPhotoLibraryAddUsageDescription带有字符串值的键,向用户解释应用程序如何使用这些数据。

Note that although the application info.plistdoes contains NSPhotoLibraryUsageDescriptionit still crashes, why?

请注意,虽然应用程序info.plist确实包含NSPhotoLibraryUsageDescription它仍然崩溃,为什么?

回答by Ahmad F

Note that although the application info.plist does contains NSPhotoLibraryUsageDescriptionit still crashes, why?

请注意,虽然应用程序 info.plist 确实包含 NSPhotoLibraryUsageDescription它仍然崩溃,为什么?

I think there is a misunderstanding when comparing NSPhotoLibraryUsageDescriptionand NSPhotoLibraryAddUsageDescription, as documented in Information Property List Key Reference:

我认为比较NSPhotoLibraryUsageDescription和时存在误解NSPhotoLibraryAddUsageDescription,如信息属性列表关键参考中所述

NSPhotoLibraryUsageDescription:

NSPhotoLibraryUsageDescription:

This key lets you describe the reason your app accessesthe user's photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.

此键可让您描述应用访问用户照片库的原因。当系统提示用户允许访问时,此字符串将作为警报的一部分显示。

It is related to letting the app to be able to access(get) the device photos library.

它与让应用程序能够访问(获取)设备照片库有关。

NSPhotoLibraryAddUsageDescription:

NSPhotoLibraryAddUsageDescription:

This key lets you describe the reason your app seeks write-only accessto the user's photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.

此键可让您描述您的应用寻求 对用户照片库进行只写访问的原因。当系统提示用户允许访问时,此字符串将作为警报的一部分显示。

It is related to letting the app to be able to write(add) photos into the device photos library.

它与让应用程序能够将照片写入(添加)到设备照片库中有关。



Obviously, to solve this crash you have to add the NSPhotoLibraryAddUsageDescriptioninto the application's plist file:

显然,要解决此崩溃问题,您必须将其添加NSPhotoLibraryAddUsageDescription到应用程序的 plist 文件中:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Our application needs permission to write photos...</string>

As property list view:

作为属性列表视图:

enter image description here

在此处输入图片说明

回答by Arunabh Das

There is a typo in the above answer. The correct plist entry should be as follows

上面的答案有一个错字。正确的plist条目应该如下

<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) needs permission to access photos on your device</string>