iOS 10.0 运行时崩溃中的 NSCameraUsageDescription?

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

NSCameraUsageDescription in iOS 10.0 runtime crash?

ioscameraplistbarcodeios-permissions

提问by user3069232

Using iOS 10.0last beta. I had tried to use Camera to scan barcode in my app, and it crashed with this runtime error.

使用iOS 10.0最后一个测试版。我曾尝试使用相机扫描我的应用程序中的条形码,但它因此运行时错误而崩溃。

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

此应用程序已崩溃,因为它试图在没有使用说明的情况下访问隐私敏感数据。应用程序的 Info.plist 必须包含一个 NSCameraUsageDescription 键和一个字符串值,向用户解释应用程序如何使用这些数据。

Put this key into the plist, but it still crashed?

把这个key放进plist,还是崩溃?

回答by Bhoopi

After iOS 10 you have to define and provide a usage description of all the system's privacy-sensitive data accessed by your app in Info.plist as below:

在 iOS 10 之后,您必须在 Info.plist 中定义并提供您的应用访问的所有系统隐私敏感数据的使用说明,如下所示:

Calendar

日历

Key    :  Privacy - Calendars Usage Description    
Value  :  $(PRODUCT_NAME) calendar events

Reminder :

提醒 :

Key    :   Privacy - Reminders Usage Description    
Value  :   $(PRODUCT_NAME) reminder use

Contact :

接触 :

Key    :   Privacy - Contacts Usage Description     
Value  :  $(PRODUCT_NAME) contact use

Photo :

照片 :

Key    :  Privacy - Photo Library Usage Description    
Value  :  $(PRODUCT_NAME) photo use

Bluetooth Sharing :

蓝牙共享:

Key    :  Privacy - Bluetooth Peripheral Usage Description     
Value  :  $(PRODUCT_NAME) Bluetooth Peripheral use

Microphone :

麦克风 :

Key    :  Privacy - Microphone Usage Description    
Value  :  $(PRODUCT_NAME) microphone use

Camera :

相机 :

Key    :  Privacy - Camera Usage Description   
Value  :  $(PRODUCT_NAME) camera use

Location :

地点 :

Key    :  Privacy - Location Always Usage Description   
Value  :  $(PRODUCT_NAME) location use

Key    :  Privacy - Location When In Use Usage Description   
Value  :  $(PRODUCT_NAME) location use

Heath :

希思:

Key    :  Privacy - Health Share Usage Description   
Value  :  $(PRODUCT_NAME) heath share use

Key    :  Privacy - Health Update Usage Description   
Value  :  $(PRODUCT_NAME) heath update use

HomeKit :

家庭套件:

Key    :  Privacy - HomeKit Usage Description   
Value  :  $(PRODUCT_NAME) home kit use

Media Library :

媒体库:

Key    :  Privacy - Media Library Usage Description   
Value  :  $(PRODUCT_NAME) media library use

Motion :

运动 :

Key    :  Privacy - Motion Usage Description   
Value  :  $(PRODUCT_NAME) motion use

Speech Recognition :

语音识别 :

Key    :  Privacy - Speech Recognition Usage Description   
Value  :  $(PRODUCT_NAME) speech use

SiriKit :

SiriKit :

Key    :  Privacy - Siri Usage Description  
Value  :  $(PRODUCT_NAME) siri use

TV Provider :

电视供应商:

Key    :  Privacy - TV Provider Usage Description   
Value  :  $(PRODUCT_NAME) tvProvider use

You can get detailed information in thislink.

您可以在链接中获取详细信息。

回答by Ramkrishna Sharma

As Apple has changed how you can access any user private data types in iOS 10.

由于 Apple 改变了您访问iOS 10.

You need to add the "Privacy - Camera usage description" key to your app's Info.plistand their usage information which is apply for your application, as in below example I had provided that I have used to scan barcodes.

您需要将“ Privacy - Camera usage description”键添加到您的应用程序Info.plist及其适用于您的应用程序的使用信息中,如下面的示例所示,我提供了用于扫描条形码的信息。

For more information please find the below screenshot.

有关更多信息,请查看以下屏幕截图。

enter image description here

在此处输入图片说明

回答by Bluewings

You have to add this below key in info.plist.

您必须在 info.plist 中添加以下键。

NSCameraUsageDescriptionOr Privacy - Camera usage description

NSCameraUsageDescription或者 Privacy - Camera usage description

And add description of usage.

并添加使用说明。

Detailed screenshots are available in this link

详细屏幕截图可在此链接中找到

回答by ayalcinkaya

Alternatively open Info.plist as source code and add this:

或者打开 Info.plist 作为源代码并添加以下内容:

<key>NSCameraUsageDescription</key>
<string>Camera usage description</string>

回答by Xeieshan

Use these raw values and copy in info.plist

使用这些原始值并复制到 info.plist

    <key>NSCalendarsUsageDescription</key>
      <string>$(PRODUCT_NAME) calendar events</string>
    <key>NSRemindersUsageDescription</key>
      <string>$(PRODUCT_NAME) reminder use</string>
    <key>NSCameraUsageDescription</key>
      <string>This app requires to access your photo library to show image on profile and send via chat</string>
    <key>NSMicrophoneUsageDescription</key>
      <string>This app requires to access your microphone to record video with your voice send via chat</string>
    <key>NSPhotoLibraryUsageDescription</key>
      <string>This app requires to access your photo library to show image on profile and send via chat</string>
    <key>NSContactsUsageDescription</key>
       <string>$(PRODUCT_NAME) contact use</string>
    <key>NSLocationAlwaysUsageDescription</key>
      <string>$(PRODUCT_NAME) location use</string>
    <key>NSLocationWhenInUseUsageDescription</key>
      <string>$(PRODUCT_NAME) location use</string>

回答by user3325025

the xcode UI has changed a bit from one version to the next so here is where you update the plist for 9.0 beta 4 if it helps Project ->Target ->Infoenter image description here

xcode UI 已从一个版本更改为下一个版本,因此如果它有助于 Project ->Target ->Info,您可以在此处更新 9.0 beta 4 的 plist在此处输入图片说明

回答by Yoku

Another instance that I faced while trying to use the camera, was that it was still busy crashing giving same _CRASHING_DUE_TO_PRIVACYeven after adding the "Camera Usage Description". After failing to get anything tangible from the call stack, switched to the "Organizer" and looked into the crash reports on the device. I found that it was in fact complaining about the privacy due to the missing "Microphone Usage Description". I added that and got rid of such a cryptic break down.

我在尝试使用相机时遇到的另一个例子是,_CRASHING_DUE_TO_PRIVACY即使添加了“相机使用说明” ,它仍然忙于崩溃。在无法从调用堆栈中获取任何有形信息后,切换到“组织者”并查看设备上的崩溃报告。我发现由于缺少“麦克风使用说明”,它实际上是在抱怨隐私。我补充说,并摆脱了这种神秘的崩溃。

回答by Vetuka

For those who are still getting the error even though you added proper keys into Info.plist:

对于那些即使您在 Info.plist 中添加了正确的键仍然出现错误的人:

Make sure you are adding the key into correct Info.plist. Newer version of xCode, apparently has 3 Info.plist.

确保您将密钥添加到正确的 Info.plist 中。较新版本的 xCode,显然有 3 个 Info.plist。

One is under folder with your app's name which solved problem for me.

一个是在您的应用程序名称的文件夹下,这为我解决了问题。

Second is under YourappnameTests and third one is under YourappnameUITests.

第二个在 YourappnameTests 下,第三个在 YourappnameUITests 下。

Hope it helps.

希望能帮助到你。

回答by Victor Tavares

If you're using Ionic, you can solve it directly from config.xmlby adding inside platform ios tag:

如果您使用的是 Ionic,您可以通过添加内部平台 ios 标签直接从config.xml解决它:

<platform name="ios">
.
.
.
    <config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
        <string>photo library usage description</string>
    </config-file>
    <config-file target="*-Info.plist" parent="NSCameraUsageDescription">
        <string>camera usage description</string>
    </config-file>
.
.
.
</platform>

I'd like to thank @BHUPI answer too.

我也想感谢@BHUPI 的回答。

回答by Mark90

I checked the plist and found it is not working, only in the "project" info, you need to add the "Privacy - Camera ....", then it should work. Hope to help you.

我检查了 plist,发现它不起作用,仅在“项目”信息中,您需要添加“隐私 - 相机 ....”,然后它应该可以工作。希望能帮到你。