31

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!

Pavel Kovalev
  • 7,521
  • 5
  • 45
  • 67

7 Answers7

35

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:

    <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

TylerH
  • 20,799
  • 66
  • 75
  • 101
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • Not sure if support has been dropped for this, but I had use the `edit-config` tag for cordova plugin camera https://github.com/apache/cordova-plugin-camera#ios-quirks – kmanzana Oct 24 '17 at 17:14
  • 1
    yeah, we are dropping support of this, but it has not been released yet. This will be done in a few days in a major release (3.0.0). Shouldn't affect you unless you install from github url instead of from npm – jcesarmobile Oct 24 '17 at 17:21
  • @jcesarmobile what about Q2? Is it possible to use localization for this string? – Pavel Kovalev Dec 12 '17 at 19:24
  • To localize usage descriptions you have to create an `InfoPlist.strings` file and localize it, but sadly Cordova doesn't support that. You can open the Xcode workspace on `platforms/ios/` and do it manually, but it could be deleted on a `cordova-ios` platform update. For more information https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html#//apple_ref/doc/uid/TP40009254-102276 – jcesarmobile Dec 12 '17 at 21:57
  • Edited the answer with information about how to do the localization in a way that won't be deleted when you remove the platform and add it again. – jcesarmobile May 14 '18 at 09:35
5

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>
chispitaos
  • 767
  • 9
  • 14
  • For me, the cordova ios config.xml `edit-config` entries weren't being updated in my xCode project. So, using the `platform` and `edit-config` tags mentioned in #2, I just needed to use `mode="overwrite" and removed `overwrite="true" and then ran `cordova prepare ios` which made the changes visible in xCode. – tyler.frankenstein Feb 05 '21 at 16:40
2

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.

bondydaa
  • 263
  • 3
  • 7
1

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

enter image description here

It save me a lot of time.

Samuel Dauzon
  • 10,744
  • 13
  • 61
  • 94
  • Could you please also share how I can access them from Cordova or reference them? And second question: Do you know how to do localization for those messages? It would be really helpful. Thanks! – Pavel Kovalev Oct 05 '18 at 18:30
  • Hi, I don't found these information. I tried many things on Cordova config or in Ionic project code but I didn't find anything which helps me. I don't need localization in my App so I can't help you. – Samuel Dauzon Oct 05 '18 at 22:34
0
$ 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.

masayang
  • 29
  • 1
  • 4
0

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.

Raghav
  • 8,772
  • 6
  • 82
  • 106
0

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
Ken Colton
  • 1,046
  • 10
  • 15