Cordova Info.plist NSCameraUsageDescription key is

2019-02-02 05:45发布

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!

8条回答
等我变得足够好
2楼-- · 2019-02-02 06:06

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)

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. :)

查看更多
Anthone
3楼-- · 2019-02-02 06:07
$ 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.

查看更多
Anthone
4楼-- · 2019-02-02 06:18

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"

enter image description here

You can keep modify the values "Allow the app to use your camera" "Allow the app to access your photos" according to your need.

查看更多
Juvenile、少年°
5楼-- · 2019-02-02 06:22

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>
查看更多
时光不老,我们不散
6楼-- · 2019-02-02 06:22

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
查看更多
疯言疯语
7楼-- · 2019-02-02 06:23

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

查看更多
登录 后发表回答