How to localize Cordova iOS projects? - ios

I've been searching on the Internet but none of the solutions I found seems to work so, my question is with Xcode 6, how we could localize a Cordova app?
The image below illustrates the problem, I tested the app in the iOS Simulator (I changed the language settings of the simulator to Spanish) but the context menu in inputs or some plugin like camera are still in English. I changed the "Localization native development region" to "es" but still in English. Also I have Localizable.strings in the es.lproj folder.

Finally I figured out after some digging and with the help of a guy that greatly assisted me in other forum, you have to put this in the project .plist this:
<key>CFBundleLocalizations</key>
<array>
<string>es</string>
</array>
Each string is the language you want to localize.

It is also possible to do this without a hook or plugin by using <edit-config> in your config.xml. Here is an example:
<platform name="ios">
<edit-config target="CFBundleLocalizations" file="*-Info.plist" mode="overwrite">
<array>
<string>en</string>
<string>es</string>
</array>
</edit-config>
</platform>
Usage of <edit-config> in config.xml was introduced in Cordova 6.4.0.

The preferred answer is correct but has the drawback to be native, i. e. you have to modify the Info*.plist after cordova prepare.
If you want to stick with the Cordova's style (which i recommend), you can use a hook or a plugin for this.
I did it with a plugin because a plugin has (from scratch) the ability to modify the native configuration's files (AndroidManifest.xml or Info*.plist).
See https://stackoverflow.com/a/27947343/2728710
What I've done :
make a new specific plugin name "cordova-plugin-config-ios"
localPlugins/cordova-plugin-config-ios/plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<plugin id="cordova-plugin-config-ios" version="0.0.1" xmlns="http://apache.org/cordova/ns/plugins/1.0">
<name>CRM Factory Cordova Localization iOS Plugin</name>
<description>A label translate example</description>
<!-- ios -->
<platform name="ios">
<config-file target="*-Info.plist" parent="CFBundleDevelopmentRegion">
<array>
<string>French</string>
</array>
</config-file>
<config-file target="*-Info.plist" parent="CFBundleLocalizations">
<array>
<string>fr_FR</string>
</array>
</config-file>
</platform>
</plugin>
make a hook add-local-plugins.sh. In it, install the specific plugin made
add-local-plugins.sh
echo "Install specific plugin for modify Info*.plist"
cordova plugin add cordova-plugin-config-ios --searchpath ${projectDir}/localPlugins/cordova-plugin-config-ios
call the hook via config.xml
config.xml
<hook src="hooks/add-local-plugins.sh" type="before_prepare" />
In my case, the hook was not mandatory but I like the freedom brought by it and to be able to log what the program did (echo part).

Go to the .plist file of any plugin and comment out:
<!-- <key>CFBundleDevelopmentRegion</key>
<string>nl</string> -->
Then the plugin will use the systems set language and region. This is likely the most practical solution for a lot of cases.

How to use iOS device settings for language:
It seems CFBundleDevelopmentRegion is always set to en_US by default (or maybe this is because I build on a laptop that has these settings) thus showing context menus, file upload dialog etc in English.
I found that setting CFBundleDevelopmentRegion to empty uses device settings for language.
Note that some plugins seem to set language, so if you cannot get it to work, check your plugins. This was tested in Ionic 5 / Angular / Cordova.
Put this in your config.xml ios section:
<platform name="ios">
<config-file parent="CFBundleDevelopmentRegion" target="*-Info.plist">
<array>
<string />
</array>
</config-file>
</platform>
Thanks to #maximillion-bartango answer for putting me on the right track with this

I post the way that i worked:
Find in the x-code the folder Resources (is placed in root)
Select the folder Resources
Then press the main menu File->New->File...
Select in section "Resource" Strings File and press Next
Then in Save As field write InfoPlist ONLY ("I" capital and "P"
capital)
Then press Create
Then select the file InfoPlist.strings that created in Resources
folder and press in the right menu the button "Localize"
Then you Select the Project from the Project Navigator and select
the The project from project list
In the info tab at the bottom you can as many as language you want
(There is in section Localizations)
The language you can see in Resources Folder
To localize the values ("key") from info.plist file you can open
with a text editor and get all the keys you want to localize
You write any key as the example in any InfoPlist.strings like the
above example
"NSLocationAlwaysAndWhenInUseUsageDescription"="blabla";
"NSLocationAlwaysUsageDescription"="blabla2";
That's all work and you have localize your info.plist file!

You can do this within the app code itself using cordova-custom-config:
<custom-config-file parent="CFBundleLocalizations" target="*-Info.plist" mode="replace">
<array>
<string>en</string>
</array>
</custom-config-file>

Adding CFBundleLocalizations works, however, you still need to manually add, or drag, the InfoPlist.strings files to the Xcode project to work.
I found this Cordova plugin completely takes over the process, https://github.com/kelvinhokk/cordova-plugin-localization-strings. So I can simply run cordova prepare and it is all set.

Related

How does iOS perform localization in Cordova / Phonegap build?

I am trying to display my app name in different languages.
English
Chinese (Simplified)
Chinese (Traditional)
I am using phonegap build to build the app so cannot use xcode.
Therefore, I have created 3 folders which contain respective InfoPlist.strings file manually on res folder like:
en.lproj/InfoPlist.strings
zh.lproj/InfoPlist.strings
zh-hant.lproj/InfoPlist.strings
Example of InfoPlist.strings file inside zh-hant.lproj folder:
My config.xml has these lines to copy to respective folder and also use it respectively.
<resource-file src="res/zh-hant.lproj" target="zh-hant.lproj" />
<resource-file src="res/zh.lproj" target="zh.lproj" />
<resource-file src="res/en.lproj" target="en.lproj" />
<!-- copy localization file -->
<resource-file src="res/zh-hant.lproj/InfoPlist.strings" target="zh-hant.lproj/InfoPlist.strings" />
<resource-file src="res/zh.lproj/InfoPlist.strings" target="zh.lproj/InfoPlist.strings" />
<resource-file src="res/en.lproj/InfoPlist.strings" target="en.lproj/InfoPlist.strings" />
<config-file platform="ios" parent="LSHasLocalizedDisplayName" mode="replace">
<true />
</config-file>
<edit-config target="CFBundleLocalizations" file="*-Info.plist" mode="overwrite">
<array>
<string>en</string> <!-- english -->
<string>zh</string> <!-- chinese (simplified) -->
<string>zh-hant</string> <!-- chinese (traditional) -->
</array>
</edit-config>
The problem is that when I install the app on iPhone the translation is not working. My current language set to English, I get the English name.
When I change language to chinese it does not reflect (translation not working, i.e still in English).
How do I fix this ? Is there anything I am missing ?
If you wish to debug localisation, you need to edit your scheme, as explained here.

How to localize app name in cordova for iOS?

I am looking for a solution to localize my app's name in:
English (EN)
Chinese (Simplified) zh-Hans
Chinese (Traditional) zh-Hant
I am using build.phonegap to build my both apps so I cannot modify the platform code but instead it has to be from either some config on config.xml or using cordova hooks or any other solution. So far I found solution for android using hooks but it will not work for iOS.
Thanks
For iOS you can do code in config.xml file.
<platform name="ios">
<edit-config target="CFBundleLocalizations" file="*-Info.plist" mode="overwrite">
<array>
<string>en</string>
<string>es</string>
</array>
</edit-config>
</platform>
Usage of <edit-config> in config.xml was introduced in Cordova 6.4.0.

Cordova iOS landscape orientation

My Cordova app never rotates to landscape mode when running on iPhone.
I've tried many solutions as putting these lines in the config.xml files:
<preference name="ios-orientation-iphone" value="portrait and landscape" />
<preference name="ios-orientation-ipad" value="portrait and landscape" />
<preference name="Orientation" value="default" />
I also put the following line inside the <platform name="ios"> block:
<preference name="Orientation" value="all" />
Then I did the following in my index.js file:
window.shouldRotateToOrientation = function (degrees) {
return true;
};
Finally, I tried to create a custom plist file in the res/native/ios folder cause I noticed than the generated plist file didn't contain these lines:
<key>UISupportedInterfaceOrientations</key>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
I don't know what to do next. Thanks
I finally did it. The trick was just to put the custom .plist file in the res/native//-Info.plist.
This link gave me the solution: Tools for Apache Cordova (VS2015): Adding custom entries to *info.plist for iOS
Yeah, this is a shortcoming of the cordova cli that creates the Xcode project -- it doesn't add those orientation tags.
A while back I had added the following to my config.xml (I'm using the PhoneGap build service currently).
<gap:config-file platform="ios" parent="UISupportedInterfaceOrientations" mode="replace">
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</gap:config-file>
There's more info on this blog post: http://phonegap.com/blog/2014/01/30/customizing-your-android-manifest-and-ios-property-list-on-phonegap-build/.
Update: I had a link the <config-file> element, but it looks like that element is for plugins (in the plugin.xml file), not for the normal build -- so it won't work.
So... your best bets are:
To programmatically adding orientation stuff, create a script that finds your .plist file and adds the following block to it if the block isn't there:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
To add it after the platform is added via cordova platform add ios, open the .xcodeproj file, go to the project node / General / Deployment info, and check all the orientations for both iPhone and iPad.
I see you've found a solution. Here's another one that uses build hooks and npm.js to do the work; the benefit is that this should work cross-platform, should you ever do development on linux or OSX. Here's more info about build hooks: http://cordova.apache.org/docs/en/latest/guide/appdev/hooks/index.html
Add the following to your config.xml file:
<platform name="ios">
<hook type="after_prepare" src="iosAfterPrepare.js" />
</platform>
Create a file named iosAfterPrepare.js in the top-level directory and copy in the following (replacing MyProject with the name of your project):
// iosAfterPrepare.js
// Node.js build script run after "cordova ios prepare" (part of cordova build).
// This adds the various orientations to the plist file for your project.
module.exports = function (context) {
var fs = require('fs'), // nodejs.org/api/fs.html
plist = require('plist'), // www.npmjs.com/package/plist
// Here you will replace "MyProject" with the name of yours,
// so that the .plist file can be found
FILEPATH = 'platforms/ios/MyProject/MyProject-Info.plist',
xml = fs.readFileSync(FILEPATH, 'utf8'),
obj = plist.parse(xml);
obj.UISupportedInterfaceOrientations = [
"UIInterfaceOrientationPortrait",
"UIInterfaceOrientationPortraitUpsideDown",
"UIInterfaceOrientationLandscapeLeft",
"UIInterfaceOrientationLandscapeRight"
];
xml = plist.build(obj);
fs.writeFileSync(FILEPATH, xml, { encoding: 'utf8' });
};
You might need to do call npm install --save plist to get the plist module on your machine (it'll complain that it can't find plist).
Call:
cordova platform rm ios
cordova platform add ios
You should see the lines in the .plist file at this point.
This worked for me in cordova v 7.0.1
<preference name="Orientation" value="default" />
in config.xml
For iOS you need to add "gap://*" property into Content Security Policy in your index.html file (two slashed are required).
For example:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data:* gap://* tel:* 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'" />
Othewise phone changes orientation only if the user interacts with OS (pressing the front button, showing the notification center with drag down or go to device settings dragging up).
ondeviceready event will neither fire without gap://* value set.
You also need to add cordova-plugin-whitelist plugin.
from corvoda-plugin-whitelist description:
gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
Tested on cordova 8.1.2

How to completely hide the status bar in iOS using Cordova?

I want to have no status bar for the Cordova app I am developing. I am nearly there, the status bar doesn't show on the splash screen. However on the first page that loads you see a flash of the status bar, before it gets hidden.
I have checked the "hide status bar" checkbox in Xcode.
I have added the cordova-plugin-statusbar plugin, and on the deviceready callback, I'm calling StatusBar.hide().
However when the splash image disappears and the first page is being rendered there is a flash of status bar prior to the page being display. It is only for a split second but looks awful.
Anybody know how the status bar can be hidden completely, without flashing up before being hidden?
Original Answer
Although I'm answering this question very late but after one full day of the search, I got this working simply so I would like to share it with others.
According to the docs (and like jcesarmobile answered):
Hiding at startup
During runtime you can use the StatusBar.hide function below, but if
you want the StatusBar to be hidden at app startup, you must modify
your app's Info.plist file.
Add/edit these two attributes if not present. Set "Status bar is
initially hidden" to "YES" and set "View controller-based status bar
appearance" to "NO". If you edit it manually without Xcode, the keys
and values are:
This requires you to modify your app's info.plist file inside platforms/ios/<app-name>/<app-name>-Info.plist file to add the following lines:
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
But that is not recommended because this will require you to save that change which might get overwritten after the build process.
(Please see the Update 2 from here if you are using the latest Cordova CLI)
So as the clean alternative you should use cordova-custom-config. According to docs:
Why should I use it?
While some platform preferences can be set via
Cordova/Phonegap in the config.xml, many (especially ones related to
newer platform releases) cannot. One solution is to manually edit the
configuration files in the platforms/ directory, however this is not
maintainable across multiple development machines or a CI environment
where subsequent build operations may overwrite your changes.
This plugin attempts to address this gap by allowing additional
platform-specific preferences to be set after the prepare operation
has completed, allowing either preferences set by Cordova to be
overridden or other unspecified preferences to be set. Since the
custom preferences are entered into the config.xml, they can be
committed to version control and therefore applied across multiple
development machines, CI environments, and maintained between builds
or even if a platform is removed and re-added.
Now, all you have to do is to run the following command for your Cordova app:
cordova plugin add cordova-custom-config --save
And add this to your config.xml file under <platform name="ios"> block:
Please refer cordova-custom-config (version > 5) plugin for more information
<custom-config-file parent="UIStatusBarHidden" platform="ios" target="*-Info.plist">
<true/>
</custom-config-file>
<custom-config-file parent="UIViewControllerBasedStatusBarAppearance" platform="ios" target="*-Info.plist">
<false/>
</custom-config-file>
Update 1 (20th Feb 2018)
If you are using cordova-custom-config plugin version < 5 then replace custom-config-file tag with config-file.
https://github.com/dpa99c/cordova-custom-config#changes-in-cordova-custom-config5
Update 2 (6th July 2018)
Since Cordova CLI 6, you now don't require to install the cordova-custom-config plugin for altering the platforms/ios/*-info.plist file. Cordova CLI has the inbuilt support of it using edit-config tag. So now you can simply add the following in your config.xml under <platform name="ios">:
<edit-config file="*-Info.plist" mode="merge" target="UIStatusBarHidden">
<true />
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="UIViewControllerBasedStatusBarAppearance">
<false />
</edit-config>
This change might fail when you build your Cordova application because it will conflict with platform/ios/ios.json file. To fix this you have two options (reference):
Option 1 (Overkill but working)
Re-add the iOS platform:
ionic cordova platform remove ios
ionic cordova platform add ios
https://issues.apache.org/jira/browse/CB-13564
Option 2 (Recommended but not working for me)
Use platform/ios/ios.json instead of *-Info.plist in the edit-config file. So the final config you have to add:
<edit-config file="platforms/ios/ios.json" mode="merge" target="UIStatusBarHidden">
<true />
</edit-config>
<edit-config file="platforms/ios/ios.json" mode="merge" target="UIViewControllerBasedStatusBarAppearance">
<false />
</edit-config>
And then do:
cordova prepare ios
EDIT:
Since Cordova CLI 6.5.0 you can use edit-config tag to write in the info.plist without a plugin.
This should hide the statusbar at startup
<edit-config file="*-Info.plist" target="UIStatusBarHidden" mode="merge">
<true/>
</edit-config>
<edit-config file="*-Info.plist" target="UIViewControllerBasedStatusBarAppearance" mode="merge">
<false/>
</edit-config>
Hiding at startup
During runtime you can use the StatusBar.hide function below, but if
you want the StatusBar to be hidden at app startup, you must modify
your app's Info.plist file.
Add/edit these two attributes if not present. Set "Status bar is
initially hidden" to "YES" and set "View controller-based status bar
appearance" to "NO". If you edit it manually without Xcode, the keys
and values are:
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
https://github.com/apache/cordova-plugin-statusbar
This way worked to me:
On your mac or VM xcode, select TARGETS->Your app
Then on INFO menu, on CUSTOM iOS TARGET PROPERTIES, add this NEW properties:
Statusbar is initially hidden -> Then set the value to YES.
View controller-based status bar appearance -> Then set the value to NO
Build and you should have no statusbar.
printscreen: http://prntscr.com/fg0jtf
I was also having the same problem for android.
It was solved by simply calling the below statusBar() function from the 'appCtrl' init() function.
Hope it will work for iOS.
$rootScope.statusBar = function(){
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
//console.log(StatusBar);
StatusBar.hide();
}

Add entry to iOS .plist file via Cordova config.xml

I am new to the Cordova CLI.
I need to perform the following steps programmatically via Cordova.
In the project .plist add a new row
Enter the following values in the new row:
Key: GDLibraryMode Type:String (default) Value:GDEnterpriseSimulation
I think I need to do this in the config.xml file in my project's root (or maybe the one in the "platforms" folder).
Can someone explain to me how to add the entry via the config.xml so that the above entry is added at compile-time?
I am using Cordova 3.3.1-0.42 (I know it is not the latest). I have already made my project and all is fine, I just need to add this entry added to the pList.
EDIT: 2/8/21
As per a comment on this question:
For anyone coming late to this, setting values in the project plist is now supported by Cordova CLI 7 and above
I don't think you can do this via straight config.xml modification. At least, I didn't see any mention of this in the docs: http://cordova.apache.org/docs/en/3.3.0/config_ref_index.md.html
I think you have to create a plugin, because they can insert plist entries: http://docs.phonegap.com/en/3.3.0/plugin_ref_spec.md.html#Plugin%20Specification
See the 'config-file element' section. Here's a guess as to what the relevant section of the plugin.xml will look like:
<platform name="ios">
<config-file target="*-Info.plist" parent="CFBundleURLTypes">
<array>
<dict>
<key>GDLibraryMode</key>
<string>GDEnterpriseSimulation</string>
</dict>
</array>
</config-file>
</platform>
Then you can install the plugin: cordova plugin add <your plugin name or file location>
I really like #james's solution using a Cordova hook. However, there are two issues. The docs state:
"we highly recommend writing your hooks using Node.js"
"/hooks directory is considered deprecated in favor of the hook elements in config.xml"
Here's a Node.js implementation using the plist NPM package:
var fs = require('fs'); // nodejs.org/api/fs.html
var plist = require('plist'); // www.npmjs.com/package/plist
var FILEPATH = 'platforms/ios/.../...-Info.plist';
module.exports = function (context) {
var xml = fs.readFileSync(FILEPATH, 'utf8');
var obj = plist.parse(xml);
obj.GDLibraryMode = 'GDEnterpriseSimulation';
xml = plist.build(obj);
fs.writeFileSync(FILEPATH, xml, { encoding: 'utf8' });
};
Of all the hook types provided by Cordova, the relevant ones for your situation are:
after_prepare
before_compile
Choose a hook type, and then add the hook to your config.xml file:
<platform name="ios">
<hook type="after_prepare" src="scripts/my-hook.js" />
</platform>
You can use the PlistBuddy utility inside a Cordova hook script to modify the *-Info.plist file.
For example, I have the following script under <project-root>/hooks/after_prepare/010_modify_plist.sh which adds a dictionary property and adds an entry within that dictionary:
#!/bin/bash
PLIST=platforms/ios/*/*-Info.plist
cat << EOF |
Add :NSAppTransportSecurity dict
Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool YES
EOF
while read line
do
/usr/libexec/PlistBuddy -c "$line" $PLIST
done
true
Be sure to make the script executable (chmod +x).
The true at the end of the script is because PlistBuddy returns with an error exit code if the key being added already exists, and doesn't provide a way to detect if the key already exists. Cordova will report a build error if the hook script exits with an error status. Better error handling is possible but a pain to implement.
These are the steps I ended up doing to enable my application to share files through itunes between devices.
1.In your application navigate to your config.xml. Type this piece into your config under the platform tag <platform name="ios">.
<config-file platform="ios" target="*-Info.plist" parent="UIFileSharingEnabled">
<true/>
</config-file>
2. Then go to your command line tool and type: cordova prepare
Uninstall and reinstall your application on your device, and you will see your app appear in itunes for you to share any files between your devices.
A few things, make sure cordova is up to date, and that you added the platform for ios.
npm install -g cordova
This command installs cordova.
cordova platform add ios
This command adds the platform for ios.
What is happening is when you run the cordova prepare command you are using Apple's Xcode SDK that is generated in the platform/ios folder. There you can see the plist file that is generated for your application, which is labeled as "yourApp-info.plist". There you can see the new key and string produced in the xml layout which looks like this:
<key>UIFileSharingEnabled</key>
<true/>
Also word of warning, my company dropped this ionic framework application into my lap a couple weeks ago (with a really short deadline). Everything I am telling you is based on couple weeks of learning. So this may not be the best practice, but I hope it helps someone out.
Edit
Link to the docs
This does seem to be possible now using the config.xml: at least some core plugin authors say so. For instance, in the docs for the Cordova Camera Plugin, they discuss the new requirement in iOS 10 that you provide a permission message string in the plist. To accomplish it, they suggest executing the plugin add command with arguments, thus:
cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="My App would like to access your camera, to take photos of your documents."
This has the result that you not only get a new <plugin> added to config.xml, but it has a <variable> child:
<plugin name="cordova-plugin-camera" spec="~2.3.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value="My App would like to access your camera, to take photos of your documents." />
</plugin>
Which then seems to correlate to the new keys in my info.plist, perhaps somehow passing the values at runtime?
<key>NSCameraUsageDescription</key>
<string/>
<key>NSPhotoLibraryUsageDescription</key>
<string/>
I'd be lying if I said that I know exactly how it works, but it seems to point the way.
UPDATE: for people want to use camera with iOS >= 10.
This mean, by normal you can config in plugin as:
<!-- ios -->
<platform name="ios">
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string></string>
</config-file>
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string></string>
</config-file>
<config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
<string></string>
</config-file>
</platform>
But for now, you can't config NSCameraUsageDescription and NSPhotoLibraryUsageDescription in plugin. You need to config them in platform -> iOS project by Xcode or in *-Info.plist file.
Since iOS 10 it's mandatory to add a NSCameraUsageDescription and
NSPhotoLibraryUsageDescription in the info.plist.
Learn more: https://www.npmjs.com/package/cordova-plugin-camera
I'm using the following in the ionic 3 without any additional plugin or imports and I think this could be helpful for others:
<platform name="ios">
<edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
<string>Location is required so we can show you your nearby projects to support.</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
<string>Camera accesss required in order to let you select profile picture from camera.</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSPhotoLibraryUsageDescription">
<string>Photo library accesss required in order to let you select profile picture from gallery / library.</string>
</edit-config>
</platform>
You can set the display name in app's plist by directly editing the ios.json in the plugins directory.
Adding the following to the config_munge.files section of the ios.json file will do the trick and it will be maintained even when using the CLI.
"*-Info.plist": {
"parents": {
"CFBundleDisplayName": [
{
"xml": "<string>RevMob Ads Cordova Plugin Demo</string>",
"count": 1
}
]
}
}
Here's a complete example
Yes, it is possible!
I am using Cordova 9.0.0 (cordova-lib#9.0.1).
For example this is the configuration file that I used to insert new string value into Info.plist :
<platform name="ios">
<edit-config file="*-Info.plist" mode="merge" target="NSMicrophoneUsageDescription">
<string>My awesome app wish to hear your awesome voice through Microphone. Not for fancy stuff, just want to hear you.</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="---Key configuration---">
<string>---string value---</string>
</edit-config>
</platform>
After that, don't forget to rebuild your staging file by running this two command in your terminal :
cordova platform rm ios
cordova platform add ios
To confirm the change, you can check the newly generated .plist file by opening them with xCode.
-Info.plist file located at :
./platform/ios/[your app name]/[your app name]-Info.plist
#TachyonVortex solution seems to be the best option but was crashing down in my case. The issue was caused by an empty NSMainNibFile field that is not right converted by the plist NPM package. In the .plist file
<key>NSMainNibFile</key>
<string></string>
<key>NSMainNibFile~ipad</key>
<string></string>
is converted to:
<key>NSMainNibFile</key>
<string>NSMainNibFile~ipad</string>
I fixed it with by adding to the script:
obj.NSMainNibFile = '';
obj['NSMainNibFile~ipad'] = '';
The script finally looks like (scripts/my-hook.js):
var fs = require('fs'); // nodejs.org/api/fs.html
var plist = require('plist'); // www.npmjs.com/package/plist
var FILEPATH = 'platforms/ios/***/***-Info.plist';
module.exports = function (context) {
var xml = fs.readFileSync(FILEPATH, 'utf8');
var obj = plist.parse(xml);
obj.GDLibraryMode = 'GDEnterpriseSimulation';
obj.NSMainNibFile = '';
obj['NSMainNibFile~ipad'] = '';
xml = plist.build(obj);
fs.writeFileSync(FILEPATH, xml, { encoding: 'utf8' });
};
and config.xml:
<platform name="ios">
<hook type="before_build" src="scripts/my-hook.js" />
</platform>
I have used this plugin to solve the problem, maybe it can help you :
https://www.npmjs.com/package/cordova-plugin-queries-schemes
If you are trying to modify a .plist in a native iOS plugin with a <config-file> tag in your plugin.xml, here is what you need to do:
Make sure your .plist is xml, not binary! You can use plutil to convert a binary .plist into xml, and commit it to version control.
plutil -convert xml1 Info.plist
The instructions for <config-file> indicate that target= is relative to the generated xcode project at platforms/ios/<project>/, but I found that I needed to prepend a wildcard character to my path to get it to work:
target="*/Resources/MyResources.bundle/Info.plist"
If you want to add a key at the top level of the .plist, you need to set parent equal to the key name, and then nest a <string> tag with the value. Using an <array> or <dict> as any examples show will cause these keys to be nested under parent.
Here is a complete example that works for me for adding multiple top level properties:
<platform name="ios">
<config-file target="*/Resources/MyResources.bundle/Info.plist" parent="MyDistribution">
<string>Cordova</string>
</config-file>
<config-file target="*/Resources/MyResources.bundle/Info.plist" parent="MyVersion">
<string>3.2.0</string>
</config-file>
</platform>
I prefer the after_prepare hook for bigger projects or if you have multiple plugins using the same permissions. But you can always go the simple way:
simply:
- remove the plugin that requires the desired permission
- add it again with --save
- in config.xml, the plugin now has a new variable with a blank description that you can fill in
- now build ios with -- release and they will be set.
you just need following steps
1.
Go to Project navigator
Select the target
Click on info from tab option other option are build setting build phase
you will see key type value
When you point on any key name you will find + and - sign
click on the + sign
write Key: GDLibraryMode in key section
Type:Stringin tyoe section
Value:GDEnterpriseSimulation in value section

Resources