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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39519773/
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 10:10:10  来源:igfitidea点击:

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

iosreact-nativeinfo.plist

提问by Murat Ozgul

Recently I started to get this error:

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

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

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

I am using React Native to build my app (I am not familiar with ios native development) and I don't know how to add this key to Info.plist

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

Can you post an example? Thanks

你能发个例子吗?谢谢

I am using npm package "react-native-camera-roll-picker": "^1.1.7"

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

enter image description here

在此处输入图片说明

回答by Murat Ozgul

Thanks @rmaddy, I added this just after other key-string pairs in Info.plist and fixed the problem:

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

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

Edit:

编辑:

I also ended up having similar problems on different components of my app. Ended up adding all these keys so far (after updating to Xcode8/iOS10):

我也最终在我的应用程序的不同组件上遇到了类似的问题。到目前为止,最终添加了所有这些键(更新到 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>

Checkout this developer.apple.comlink for full listof property list key references.

查看此developer.apple.com链接以获取属性列表关键参考的完整列表

Full List:

完整列表:

Apple Music:

苹果音乐:

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

Bluetooth:

蓝牙:

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

Calendar:

日历:

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

Camera:

相机:

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

Contacts:

联系人:

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

Health Share:

健康分享:

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

Health Update:

健康更新:

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

Home Kit:

家庭套件:

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

Location:

地点:

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

Location (Always):

位置(始终):

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

Location (When in use):

位置(使用时):

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

Microphone:

麦克风:

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

Motion (Accelerometer):

运动(加速度计):

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

NFC (Near-field communication):

NFC(近场通信):

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

Photo Library:

照片库:

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

Photo Library (Write-only access):

照片库(只写访问权限):

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

Reminders:

提醒:

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

Speech Recognition:

语音识别:

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

回答by Bright Future

MY FAVORITE WAY TO DO IT

我最喜欢的方式

1. Open info.plist

1. 打开 info.plist

enter image description here

在此处输入图片说明

2. Click this button to add a new key

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

enter image description here

在此处输入图片说明

3. Scroll down to findPrivacy - Photo Library Usage Description

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

enter image description here

在此处输入图片说明

4. Select it, then add your description on the right

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

enter image description here

在此处输入图片说明

回答by Dinesh Vaitage

Add following code in info.plist file

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

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

enter image description here

在此处输入图片说明

回答by Reza.Ab

You need to paste these two in your info.plist, The only way that worked in iOS 11 for me.

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

回答by Ori

For camera access use:

对于相机访问使用:

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

回答by Shanu Singh

In order to save or retrieve an image from the camera roll. Additionally, you need to ask the user for the permission otherwise you'll get this error or your app may get crashed. To save yourself from this add this into your info.plist

为了从相机胶卷中保存或检索图像。此外,您需要征求用户的许可,否则您会收到此错误或您的应用程序可能会崩溃。为了避免这种情况,请将其添加到您的 info.plist 中

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

In the case of Xamarin.iOS

对于 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".

回答by Moises Hilario

If you added the key-string pairs in Info.plist (see Murat's answer above) and still getting the error, try to check if the target you're currently working on has the keys.

如果您在 Info.plist 中添加了键字符串对(请参阅上面的 Murat 的回答)并且仍然收到错误,请尝试检查您当前正在处理的目标是否具有键。

In my case I had 2 targets (dev and development). I added the keys in the editor, but it only works for the main target and I was testing on development target. So I had to open XCode, click on the project > Info > Add the key-pair for the development target there.

就我而言,我有 2 个目标(开发和开发)。我在编辑器中添加了键,但它只适用于主要目标,我正在测试开发目标。所以我必须打开 XCode,点击项目 > 信息 > 在那里添加开发目标的密钥对。

回答by iOS

https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html

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

Open plist file and this code

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