ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

`ionic cordova platform add ios` not copying variables from `config.xml`

Open andrefa opened this issue 9 years ago • 17 comments

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:

  1. add variables info do config.xml
  2. 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.

andrefa avatar May 12 '17 11:05 andrefa

Is this done with a hook? I may need more information.

imhoffd avatar May 12 '17 19:05 imhoffd

On ionic cli 2, this is done on platform add and/or ionic state restore, but state restore was removed..

andrefa avatar May 12 '17 19:05 andrefa

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>

imhoffd avatar May 12 '17 21:05 imhoffd

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

andrefa avatar May 15 '17 12:05 andrefa

This is also broken for me! Having to manually copy them into the plist and build from xcode for now.

CookieCookson avatar May 22 '17 12:05 CookieCookson

@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.

imhoffd avatar May 22 '17 22:05 imhoffd

@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.

CookieCookson avatar May 23 '17 08:05 CookieCookson

@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.

CookieCookson avatar May 23 '17 09:05 CookieCookson

I also faced with the same issue. Privacy descriptions is not copied from config.xml

ErbolLab avatar Jun 19 '17 13:06 ErbolLab

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.

elsesiy avatar Jun 19 '17 15:06 elsesiy

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.

CookieCookson avatar Jun 22 '17 08:06 CookieCookson

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"
        }
    }
}

ErbolLab avatar Jun 22 '17 09:06 ErbolLab

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.

janpio avatar Jun 22 '17 11:06 janpio

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.

wacton avatar Jul 04 '17 00:07 wacton

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"

ddoerr avatar Jan 30 '18 13:01 ddoerr

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

`

ShiChuanTaylors avatar Feb 03 '18 17:02 ShiChuanTaylors

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

lentyaishe avatar May 10 '18 17:05 lentyaishe