ios Cordova Info.plist NSCameraUsageDescription 密钥丢失
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39566952/
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
Cordova Info.plist NSCameraUsageDescription key is missing
提问by Pavel Kovalev
After recent changes Apple requires specific keys if your app attempts to access privacy-sensitive data. So I added NSCameraUsageDescription key in my config.xml like this:
在最近的更改之后,如果您的应用程序尝试访问隐私敏感数据,Apple 需要特定的密钥。所以我在我的 config.xml 中添加了 NSCameraUsageDescription 键,如下所示:
<platform name="ios">
<config-file parent="NSCameraUsageDescription" target="*-Info.plist">
<string>We are using a camera to </string>
</config-file>
</platform>
Then
然后
cordova build ios --release --device
produces the ipa which apparently doesn't have the right info in info.plist. It feels like I'm missing something.
产生的 ipa 显然在 info.plist 中没有正确的信息。感觉就像我错过了一些东西。
Question 1:What do I need to put into config.xml to solve NSCameraUsageDescription issue? Question 2:Is it possible to use localization for this string?
问题 1:我需要在 config.xml 中添加什么来解决 NSCameraUsageDescription 问题? 问题 2:是否可以对这个字符串使用本地化?
Thank you!
谢谢!
回答by jcesarmobile
NEW ANSWER:
新答案:
Since Cordova CLI 6.5.0 you can write in the info.plist
directly by using the edit-config
tag in the config.xml
like this:
从 Cordova CLI 6.5.0 开始,您可以info.plist
直接使用edit-config
标签编写,config.xml
如下所示:
<string>your usage message</string>
</edit-config>
But make sure you are using latest version of the plugins or values might be overwritten by the plugin variables.
但请确保您使用的是最新版本的插件,否则插件变量可能会覆盖值。
For localizations you can use the resource-file
tag and InfoPlist.strings files like in this plugin (but you don't need the plugin, resource-file tag is supported from the config.xml)
对于本地化,您可以使用resource-file
该插件中的标签和 InfoPlist.strings 文件(但您不需要插件,config.xml 支持资源文件标签)
https://github.com/MBuchalik/cordova-plugin-ios-permissions
https://github.com/MBuchalik/cordova-plugin-ios-permissions
OLD ANSWER:
旧答案:
You can't write on the info.plist
from the config.xml
using the config-file
tag yet (it's being worked on)
你不能写info.plist
在config.xml
使用config-file
标签,但(它被上工作)
Latest version of the camera plugin allows you to add the NSCameraUsageDescription
when you install the plugin
cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="your usage message"
最新版本的相机插件允许您NSCameraUsageDescription
在安装插件时添加
cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="your usage message"
Right now it's not possible to localize this string
现在无法本地化此字符串
回答by Pavel Kovalev
Here are results of my own research:
以下是我自己的研究结果:
- Yes, you can modify info.plistfrom the config.xmlfileusing the config-file tag, butyou have to use a plugin for that (cordova custom config)and follow the instructions religiously.
- However, probably a better option is to use plugin.xmlto do the same thing. More about it you can read here (modifying info plist from plugin.xml)
- Another option as @jcesarmobile mentioned - current camera plugin may support it like cordova plugin camera(this solution is specific to the plugin)
- Yes, it is possible to localize a string inside the info.plist filebutit requires to use xcode for that. I'm not sure how to localize a string inside the info.plist file using Cordova config.xmlor plugin.xml
- 是的,您可以使用 config-file 标记从config.xml文件中修改info.plist,但是您必须为此使用插件 (cordova 自定义配置)并严格按照说明进行操作。
- 但是,可能更好的选择是使用plugin.xml来做同样的事情。您可以在此处阅读更多相关信息(从 plugin.xml 修改信息 plist)
- @jcesarmobile 提到的另一个选项 - 当前的相机插件可能像cordova插件相机一样支持它(此解决方案特定于插件)
- 是的,可以在 info.plist 文件中本地化一个字符串,但它需要为此使用 xcode。我不确定如何使用 Cordova config.xml或plugin.xml本地化 info.plist 文件中的字符串
Please, correct me if I wrong. More info on the localization directly from config.xmlis appreciated.
如果我错了,请纠正我。直接从config.xml获取有关本地化的更多信息表示赞赏。
Personally, I don't like the idea to use a custom plugin to modify an info.plistfile. It feels like with every new plugin I use make my app more and more fragile. :)
就个人而言,我不喜欢使用自定义插件来修改info.plist文件的想法。感觉就像我使用的每一个新插件都会让我的应用程序变得越来越脆弱。:)
回答by Vero O
First, this works for me with Cli-7.1.0 after apple rejects my ipa.
首先,在苹果拒绝我的 ipa 后,这对我使用 Cli-7.1.0 有效。
1) In your code, if you use for ex. cordova-plugin-barcodescanner and cordova-plugin-camera and cordova-plugin-ios-camera-permissions all the variables CAMERA_USAGE_DESCRIPTION, PHOTOLIBRARY_USAGE_DESCRIPTION should have the same string inside. If one of them is different apple rejects your ipa, because phonegap use the default variable .
1)在您的代码中,如果您使用 for ex。cordova-plugin-barcodescanner 和 cordova-plugin-camera 和 cordova-plugin-ios-camera-permissions所有变量 CAMERA_USAGE_DESCRIPTION, PHOTOLIBRARY_USAGE_DESCRIPTION 里面应该有相同的字符串。如果其中之一是不同的,苹果会拒绝您的 ipa,因为 phonegap 使用默认变量 。
ej:
ej:
<plugin name="cordova-plugin-ios-camera-permissions" >
<variable name="CAMERA_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
</plugin><!-- spec="1.0.3" !-->
<plugin name="cordova-plugin-camera" >
<variable name="CAMERA_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
<gap:plugin name="cordova-plugin-image-picker" source="npm" />
<gap:plugin name="cordova-plugin-base64-joewsh" source="npm" /> <!-- convertir a base64 los files !-->
<gap:plugin name="cordova-plugin-barcodescanner" source="npm" spec="0.7.0" >
<variable name="CAMERA_USAGE_DESCRIPTION" value="YOUR-PERMISSION-REQUEST" />
</gap:plugin>
2) add this code (remember to use the same string in the variables, as I mention before):
2)添加此代码(记住在变量中使用相同的字符串,正如我之前提到的):
<platform name="ios">
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge" overwrite="true">
<string>YOUR-PERMISSION-REQUEST</string>
</edit-config>
<edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge" overwrite="true" >
<string>YOUR-PERMISSION-REQUEST</string>
</edit-config>
<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge" overwrite="true">
<string>YOUR-PERMISSION-REQUEST</string>
</edit-config>
</platform>
回答by bondydaa
You can manually edit the .plist file within your cordova project if you wish. This worked for me but since this is a generated file I do worry at some point my changes might get over written.
如果您愿意,您可以在您的cordova 项目中手动编辑.plist 文件。这对我有用,但由于这是一个生成的文件,我确实担心在某些时候我的更改可能会被覆盖。
But onto helping!
但是到帮助!
The .plist file should be located within your Cordova project within the /platforms/ios/[Cordova Project Name]/[Cordova Project Name]-Info.plist
. You can also open up the project in Xcode and along the left hand side click the Magnifier icon which will let you search for files in the project. If you enter in info.plist
it should return a result that shows something like:
.plist 文件应位于/platforms/ios/[Cordova Project Name]/[Cordova Project Name]-Info.plist
. 您还可以在 Xcode 中打开项目,然后在左侧单击放大镜图标,这将让您搜索项目中的文件。如果你输入info.plist
它应该返回一个结果,显示如下:
INFOPLIST_FILE = [Some]/[Path]/[Cordova Project Name]-Info.plist
INFOPLIST_FILE = [Some]/[Path]/[Cordova Project Name]-Info.plist
This path should be relative to your Cordova project install so searching within your project should lead you to the correct file.
此路径应该相对于您的 Cordova 项目安装,因此在您的项目中搜索应该会引导您找到正确的文件。
I opened up this file in my editor and added the following lines just inside the first opening <dict>
tag:
我在编辑器中打开了这个文件,并在第一个开始<dict>
标签内添加了以下几行:
<key>NSCameraUsageDescription</key>
<string>Uses camera to allow video chatting between two clients</string>
<key>NSCameraUsageDescription</key>
<string>Uses camera to allow video chatting between two clients</string>
I was able to submit and have my build show up and stayin itunesconnect. Currently still waiting app review.
我能够提交并显示我的构建并留在 itunesconnect 中。目前仍在等待应用程序审核。
I did run a cordova prepare ios
just to test if my changes would get over written which they did not so it looks like you should be able to do this and not worry about it but be weary of other devs installing your application and running into the same issue. I just copied my updated .plist file into the root of my repo and made note of it in the readme.
我确实运行了一个cordova prepare ios
just 来测试我的更改是否会被覆盖而他们没有这样做,所以看起来您应该能够做到这一点而不必担心,但会厌倦其他开发人员安装您的应用程序并遇到相同的问题。我只是将我更新的 .plist 文件复制到我的 repo 的根目录中,并在自述文件中记下了它。
回答by Samuel Dauzon
回答by Ken Colton
For iOS 10/11, you can use cordova-plugin-ios-camera-permissionsas a shortcut.
对于 iOS 10/11,您可以使用cordova-plugin-ios-camera-permissions作为快捷方式。
Provides defaults and clear documentation for how to provide customized messages.
提供有关如何提供自定义消息的默认值和清晰的文档。
cordova plugin add cordova-plugin-ios-camera-permissions --save
If you have already setup iOS platform, removing and re-adding may be required.
如果您已经设置了 iOS 平台,则可能需要删除和重新添加。
$ cordova platform rm ios
$ cordova platform add ios
回答by masayang
$ cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="this app will use your camera" --variable PHOTOLIBRARY_USAGE_DESCRIPTION="this app will access to your photo library"
You need to read inside of ./plugins/plugin-what-ever/plugin.xml to see what kind of key names are supported.
您需要阅读 ./plugins/plugin-what-ever/plugin.xml 的内部内容以查看支持的键名类型。
回答by Raghav
Go to your project >> Open Terminal there
转到您的项目 >> 在那里打开终端
and run this command
并运行此命令
cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="Allow the app to use your camera" --variable PHOTOLIBRARY_USAGE_DESCRIPTION="Allow the app to access your photos"
You can keep modify the values "Allow the app to use your camera" "Allow the app to access your photos" according to your need.
您可以根据需要不断修改“允许应用程序使用您的相机”“允许应用程序访问您的照片”的值。