“NSPhotoLibraryUsageDescription”键必须在Info.plist中出现以使用相机胶卷。

209

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

NSPhotoLibraryUsageDescription键必须出现在Info.plist中才能使用照片库。

我正在使用React Native构建我的应用程序(我不熟悉iOS本地开发),我不知道如何将此键添加到Info.plist中。

你能否提供一个例子?谢谢。

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

enter image description here


1
请参考 https://dev59.com/GFkS5IYBdhLWcg3w25sM#39476283 以获取在 Info.plist 中添加内容的示例。此外,只需搜索“NSPhotoLibraryUsageDescription”,您就会找到大量的示例。 - rmaddy
12个回答

535
感谢 @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链接,获取属性列表关键引用的完整列表。

完整列表:

Apple Music:

<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>

面部识别:

<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>

15
我一直在使用这个字符串:"此应用程序不需要访问照片库。" - Daniel T.
我在info.plist文件中添加了键和字符串,然后使用终端构建应用程序,但所有这些更改都被删除了。请指导一下。 - Dinesh Vaitage
我已经添加了这个,但它仍然以相同的错误崩溃。为什么会发生这种情况? - fish40
1
在 Ionic 中如何找到 info.plist 文件?我找不到它。 - Anuj

85

我的最爱方式

1. 打开 info.plist

进入图片描述

2. 点击此按钮以添加新的键

进入图片描述

3. 滚动到底部找到 隐私-相册使用说明

进入图片描述

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

进入图片描述


5
@fish40 或许你可以尝试点击“项目目标信息”,然后将其添加到那里,看看会发生什么? - Bright
20
你的关键描述让我开心极了 XD。 - Fareed Alnamrouti
2
使用说明让我感到很有趣。修复了我的问题,所以非常开心! - James Dunne
1
在哪里可以找到info.plist文件?我找不到它。 - Anuj
@Anuj请查看此处,了解如何找到info.plist文件。 - Fotios Tsakiris
显示剩余2条评论

19

截止至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>

18
在 info.plist 文件中添加以下代码。
<key>NSPhotoLibraryUsageDescription</key>
<string>My description about why I need this capability</string>

输入图片描述


2
这正是我所需要的...通过源代码,我终于成功上传了我的应用程序!谢谢 :) - BvdVen
很奇怪这个方法可行了,但其他尝试都没用,也许只是 Xcode 9 beta 的一个 bug。非常感谢!!! - JohnV
欢迎,很高兴它对你有所帮助。 - Dinesh Vaitage

16

你需要将这两个粘贴到你的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>

1
如果您正在请求将内容添加到照片库,则需要后者。 文档 - stephen.hanson

5

要访问摄像头,请使用以下方法:

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

3

我之前在我的IONIC 4项目中遇到了同样的问题。当我上传我的IPA文件时,App Store Connect给出了这些警告。

enter image description here

我通过以下步骤解决了“info.plist文件中缺少Purpose String”问题。希望这对您也有用。
  1. 进入您的“info.plist”文件。

enter image description here

  1. 找到名为 Privacy - Photo Library Usage Description 的键。如果没有,请添加一个新的,并赋值如下图所示。

enter image description here

谢谢。


1
如果您在Info.plist中添加了键-值对(请参见Murat的答案),但仍然出现错误,请检查您当前正在使用的目标是否具有这些键。在我的情况下,我有两个目标(dev和development)。我在编辑器中添加了键,但它只适用于主目标,而我正在测试开发目标。因此,我必须打开XCode,单击项目>信息>在那里为开发目标添加键对。

1
这也是我的情况。谢谢! - Sampath

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

1
为了从相机胶卷中保存或检索图像。此外,您需要请求用户的权限,否则将出现错误或应用程序可能会崩溃。为了避免这种情况,请将以下内容添加到您的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".

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接