可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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:
<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.
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?
Thank you!
回答1:
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:
<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
<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)
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)
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"
Right now it's not possible to localize this string
回答2:
Here are results of my own research:
- Yes, you can modify info.plist from the config.xml file
using the config-file tag, but you have to use a plugin for that
(cordova custom config) and follow the instructions religiously.
- However, probably a better option is to use plugin.xml to 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 file but it requires to use xcode for that. I'm not sure how to localize a string inside the info.plist file using Cordova config.xml or plugin.xml
Please, correct me if I wrong. More info on the localization directly from config.xml is appreciated.
Personally, I don't like the idea to use a custom plugin to modify an info.plist file. It feels like with every new plugin I use make my app more and more fragile. :)
回答3:
First, this works for me with Cli-7.1.0 after apple rejects my ipa.
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 .
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):
<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>
回答4:
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.
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:
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.
I opened up this file in my editor and added the following lines just inside the first opening <dict>
tag:
<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 stay in itunesconnect. Currently still waiting app review.
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.
回答5:
$ 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.
回答6:
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.
回答7:
For iOS 10/11, you can use cordova-plugin-ios-camera-permissions as a shortcut.
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.
$ cordova platform rm ios
$ cordova platform add ios
回答8:
I searched a lot of time and tried many solutions without success.
Finally, I defined these data with Xcode in Info tab on the line
Privacy - Camera usage description
It save me a lot of time.