繁体   English   中英

NSPhotoLibraryUsageDescription 键必须存在于 Info.plist 中才能使用相机胶卷

[英]NSPhotoLibraryUsageDescription key must be present in Info.plist to use camera roll

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

NSPhotoLibraryUsageDescription 键必须存在于 Info.plist 中才能使用相机胶卷。

我正在使用 React Native 来构建我的应用程序(我不熟悉 ios 本机开发)并且我不知道如何将此键添加到 Info.plist

你能发个例子吗? 谢谢

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

在此处输入图片说明

感谢@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>

我最喜欢的方式

1.打开info.plist

在此处输入图片说明

2.单击此按钮添加新密钥

在此处输入图片说明

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

在此处输入图片说明

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

在此处输入图片说明

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

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

在此处输入图片说明

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

对于相机访问,请使用:

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

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

几天前,我的 IONIC 4 项目也遇到了同样的问题。 当我上传 IPA 时,我从 App Store Connect 收到此警告。

在此处输入图片说明

我通过以下步骤修复了“info.plist 中缺少目的字符串”问题。 希望它也适合你。

  1. 转到您的“info.plist”文件。

在此处输入图片说明

  1. 找到这个键,叫做Privacy - Photo Library Usage Description 如果它不存在,请添加一个新的值,如下图所示。

在此处输入图片说明

谢谢。

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

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中添加了密钥-字符串对( 请参阅上面的Murat的答案 ),但仍然出现错误,请尝试检查您当前正在处理的目标是否具有密钥。

就我而言,我有两个目标(开发和开发)。 我在编辑器中添加了键,但是它仅适用于主要目标,并且我正在测试开发目标。 因此,我不得不打开XCode,单击项目> Info>在此处添加开发目标的密钥对。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM