最近,我开始出现此错误:
要使用相机胶卷,Info.plist中必须存在NSPhotoLibraryUsageDescription密钥。
我正在使用React Native来构建我的应用程序(我不熟悉ios本机开发),而且我不知道如何将此密钥添加到Info.plist
你能举个例子吗?谢谢
我正在使用npm包 "react-native-camera-roll-picker": "^1.1.7"
最近,我开始出现此错误:
要使用相机胶卷,Info.plist中必须存在NSPhotoLibraryUsageDescription密钥。
我正在使用React Native来构建我的应用程序(我不熟悉ios本机开发),而且我不知道如何将此密钥添加到Info.plist
你能举个例子吗?谢谢
我正在使用npm包 "react-native-camera-roll-picker": "^1.1.7"
Answers:
感谢@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>
在info.plist文件中添加以下代码
<key>NSPhotoLibraryUsageDescription</key>
<string>My description about why I need this capability</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".
"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>在此处添加开发目标的密钥对。
NSPhotoLibraryUsageDescription
,您就会发现很多示例。