`ionic cordova platform add ios` not copying variables from `config.xml`
Short description of the problem:
ionic cordova platform add ios not copying variables from config.xml to <app>-info.plist file.
Variables:
<plugin name="cordova-plugin-camera" spec="2.4.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value="My Description"/>
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="My Description"/>
</plugin>
What behavior are you expecting?
Have those variables on info.plist file as below
<key>NSCameraUsageDescription</key>
<string>My Description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>My Description</string>
Steps to reproduce:
- add variables info do config.xml
ionic cordova platform add ios
Post the output of ionic info below please
global packages:
@ionic/cli-utils : 1.0.0
Cordova CLI : 6.5.0
Ionic CLI : 3.0.0
local packages:
@ionic/app-scripts : 1.3.7
@ionic/cli-plugin-cordova : 1.0.0
@ionic/cli-plugin-ionic-angular : 1.0.0
Ionic Framework : ionic-angular 3.1.1
System:
Node : v7.9.0
OS : macOS Sierra
Xcode : Xcode 8.3.2 Build version 8E2002
ios-deploy : 1.9.1
ios-sim : 5.0.13
No error occur during the build, but deploy to Itunes connect fails because of lack of information.
Is this done with a hook? I may need more information.
On ionic cli 2, this is done on platform add and/or ionic state restore, but state restore was removed..
We don't do much on top of just running cordova platform add ios directly. This is a Cordova issue. Additionally, I'm unable to reproduce.
$ ionic cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="your usage message" --variable PHOTOLIBRARY_USAGE_DESCRIPTION="your usage message"`
contents of platforms/ios/MyApp/MyApp-Info.plist contains:
<key>NSCameraUsageDescription</key>
<string>your usage message</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>your usage message</string>
the problem is not on install, is on ionic cordova build ios, which deletes platforms variables from MyApp-Info.plist file. This was working fine
This is also broken for me! Having to manually copy them into the plist and build from xcode for now.
@andrefa @CookieCookson Please help me to reproduce this issue.
On a new ionic project, I put this in my config.xml:
<plugin name="cordova-plugin-camera" spec="2.4.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value="My Description"/>
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="My Description"/>
</plugin>
Then:
$ ionic cordova platform add ios
Then it finds the variables in the plist file:
$ grep -R NSCam .
Binary file ./build/emulator/MyApp.app/Info.plist matches
./ios.json: "NSCameraUsageDescription": [
./MyApp/MyApp-Info.plist: <key>NSCameraUsageDescription</key>
After I build with ionic cordova build ios, the variables still exist in the plist file.
@dwieeb - I'll try and create a repo today that reproduces the issue. I managed to get it to pull through ONE of the plugins descriptions and not the other after doing a platform rm/add.
@dwieeb In typical fashion, I was not able to reproduce this on a new project. My original project is still doing it, however after cloning the project from source into a different folder and following the standard install procedure it copies across all of the plist entries correctly. Not sure if its a mis-installed node package or the if cordova 6 projects just don't like being updated to 7.
I also faced with the same issue. Privacy descriptions is not copied from config.xml
Same here, I do have custom plugins that should be restored and platforms added via ionic cordova prepare. Unfortunately the CLI crashes while installing the plugins because of supposedly missing variables (both provided via config.xml).
Edit: Actually it doesn't matter if provided via config.xml or package.json, both fail. I'm using the latest version of cordova, ionic and all other dependencies.
For anyone else still having this issue - I ended up getting it to work by cloning my project to a new folder and re-installing the platforms.
I found the root of the problem, seems like ionic reads plist details from package.json instead of config.xml
so, add something like this into your package json:
"cordova": {
"platforms": [
"android",
"ios"
],
"plugins": {
"cordova-plugin-camera": {
"CAMERA_USAGE_DESCRIPTION": "To take photo"
},
"cordova-plugin-photo-library": {
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "To choose photos"
}
}
}
Please provide the exact list of commands executed and things done so someone can actually reproduce this. Also include your ionic info output so we know which Cordova version (which is actually doing all that stuff, Ionic is only calling this...) you are using and if you are on current software.
I had the same problem.
It started happening after I removed all my plugins and when re-adding them I neglected to add the variables to the plugin add command.
Afterwards I tried updating the package.json and config.xml with the correct descriptions, without any luck, even tried removing and adding the platform again.
The only way I could get it to work is to remove the plugin again and add it with the variable options.
The only thing that worked for me:
ionic cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="Your text" --variable PHOTOLIBRARY_USAGE_DESCRIPTION="Your text"
I was able to reproduce this.. I am using the cordova-plugin-camera and cordova-plugin-geolocation with the variables. However, when I checked the info.plist file xcworkspace via XCode, I did not see any of the variable is included..
Here is my ionic info ` cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.1
ionic (Ionic CLI) : 3.19.1
global packages:
cordova (Cordova CLI) : 8.0.0
local packages:
@ionic/app-scripts : 3.1.8
Cordova Platforms : android 6.4.0 ios
Ionic Framework : ionic-angular 3.8.0
System:
Android SDK Tools : 26.1.1
ios-deploy : 1.9.2
ios-sim : 4.1.1
Node : v7.6.0
npm : 4.1.2
OS : macOS High Sierra
Xcode : Xcode 9.2 Build version 9C40b
Environment Variables:
ANDROID_HOME : /Users/ting/Library/Android/sdk
Misc:
backend : pro
`
In my setup the problem was that I had another plugin (cordova-plugin-photo-library) that erased the variables values by its defaults which were empty strings.
So my suggestion is to check whether you have other plugins added to your solution that may affect the same records in .plist file. In order to do so check all relevant plugins in your project for plugin.xml file and a config-file record (that will affect the *-Info.plist with a specific property, i.e. NSCameraUsageDescription) under <platform name="ios"> section.
Another solution would be to affect the .plist file directly in the following manner in config.xml:
<edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge">
<string>YOUR text here</string>
</edit-config>
<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
<string>YOUR text here</string>
</edit-config>
But I prefer the first option since it's plugin dependable and in case you will no longer need the plugin in the future its variables will be gone during the plugin removal.
Have fun