NSPhotoLibraryUsageDescription密钥必须存在于Info.plist中才能使用Camera Roll

最近我开始得到这个错误:

NSPhotoLibraryUsageDescription密钥必须存在于info.plist中 使用相机胶卷.

我正在使用React Native来构建我的应用程序(我不熟悉IOS原生开发),我不知道如何将此键添加到info.plist

你能举个例子吗?谢谢

我正在使用npm包"react-native-camera-roll-picker": "^1.1.7"

enter image description here

205168 次浏览

谢谢@rmaddy,我在info.plist中的其他键字符串对之后添加了这个,并解决了这个问题:

<key>NSPhotoLibraryUsageDescription</key>
<string>Photo Library Access Warning</string>

编辑:

我的应用程序的不同组件也出现了类似的问题。到目前为止(在更新到Xcode8/iOS10之后),最终添加了所有这些密钥:

<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app does not require access to the microphone.</string>
<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera.</string>

签出此developer.apple.com链接完整列表属性列表键参考。

完整列表:

苹果音乐:

<key>NSAppleMusicUsageDescription</key>
<string>My description about why I need this capability</string>

蓝牙:

<key>NSBluetoothPeripheralUsageDescription</key>
<string>My description about why I need this capability</string>

行事历:

<key>NSCalendarsUsageDescription</key>
<string>My description about why I need this capability</string>

照相机

<key>NSCameraUsageDescription</key>
<string>My description about why I need this capability</string>

联系方式:

<key>NSContactsUsageDescription</key>
<string>My description about why I need this capability</string>

FaceId:

<key>NSFaceIDUsageDescription</key>
<string>My description about why I need this capability</string>

健康分享:

<key>NSHealthShareUsageDescription</key>
<string>My description about why I need this capability</string>

运行状况更新:

<key>NSHealthUpdateUsageDescription</key>
<string>My description about why I need this capability</string>

首页套件:

<key>NSHomeKitUsageDescription</key>
<string>My description about why I need this capability</string>

地点:

<key>NSLocationUsageDescription</key>
<string>My description about why I need this capability</string>

位置(始终):

<key>NSLocationAlwaysUsageDescription</key>
<string>My description about why I need this capability</string>

位置(使用时):

<key>NSLocationWhenInUseUsageDescription</key>
<string>My description about why I need this capability</string>

话筒:

<key>NSMicrophoneUsageDescription</key>
<string>My description about why I need this capability</string>

运动(加速计):

<key>NSMotionUsageDescription</key>
<string>My description about why I need this capability</string>

NFC(近场通信):

<key>NFCReaderUsageDescription</key>
<string>My description about why I need this capability</string>

照片库:

<key>NSPhotoLibraryUsageDescription</key>
<string>My description about why I need this capability</string>

照片库(只写访问):

<key>NSPhotoLibraryAddUsageDescription</key>
<string>My description about why I need this capability</string>

提醒事项:

<key>NSRemindersUsageDescription</key>
<string>My description about why I need this capability</string>

Siri:

<key>NSSiriUsageDescription</key>
<string>My description about why I need this capability</string>

语音识别:

<key>NSSpeechRecognitionUsageDescription</key>
<string>My description about why I need this capability</string>

对于摄像机访问使用:

<key>NSCameraUsageDescription</key>
<string>Camera Access Warning</string>

我最喜欢的方法

打开info.plist

enter image description here

单击此按钮可添加新密钥

enter image description here

3.向下滚动查找隐私-照片库使用说明

enter image description here

4.选择它,然后在右侧添加您的描述

enter image description here

在info.plist文件中添加以下代码

<key>NSPhotoLibraryUsageDescription</key>
<string>My description about why I need this capability</string>

enter image description here

你需要将这两个粘贴到你的info.plist中,这是我在IOS 11中使用的唯一方法。

    <key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>


<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app requires access to the photo library.</string>

https://developer.apple.com/library/content/documentation/general/reference/infoplistkeyreference/articles/cocoakeys.html.

"Privacy - Photo Library Additions Usage Description" for iOS 11 and later


"Privacy - Photo Library Usage Description" for iOS 6.0 and later

打开plist文件和此代码

<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>


<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app requires access to the photo library.</string>

以便保存或检索来自照相机胶卷的图像。此外,你需要询问用户的权限,否则你会得到这个错误,或者你的应用程序可能会崩溃。为了避免这种情况,请将其添加到您的info.plist中

<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app requires read and write permission from the user.</string>

在xamarin.IOS的情况下

 if you're adding it from the generic editor then "Privacy - Photo Library Additions Usage Description" will be the given option you will find out instead of "NSPhotoLibraryAddUsageDescription".

如果您在info.plist(见上面缪拉的回答。)中添加了键字符串对,但仍然出现错误,请尝试检查您当前正在处理的目标是否具有这些键。

在我的例子中,我有两个目标(开发和发展)。我在编辑器中添加了键,但它只适用于主目标,并且我正在对开发目标进行测试。所以我必须打开Xcode,点击项目>信息>添加开发目标的密钥对。

几天前,我的爱奥尼亚4项目也遇到了同样的问题。当我上传我的IPA时,我收到了来自App Store Connect的警告。

enter image description here

我修复了info.plist";中缺少的目的字符串通过以下步骤发布。希望它对你也有用。

  1. 转到您的";info.plist";文件。

enter image description here

  1. 查找此键,称为Privacy - Photo Library Usage Description。如果它没有出现在那里,添加一个新的和它的价值,如下图。

enter image description here

谢谢。

使用NSCameraUsageDescription时,用户可以访问相机并从照片库中选择图像。所以我不需要NSPhotoLibraryUsageDescription,对吗?

截至2021年8月, 我们不仅要加上这一点:

<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to photo library so that photos can be selected</string>

但还需要将其添加到IOS文件夹内的info.plist文件中才能正常工作

<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app requires access to the photo library.</string>