How to add specific configuration parameters to iOS -Info.plist and AndroidManifest.xml for your Cordova app
In my last Cordova project, I needed to add some specific values to the iOS -Info.plist
file, as there was no parameter to do that in the Cordova config.xml
. The problem was pretty obvious: each time I modified the config.xml file, the -Info.plist
was overridden and the values I entered manually were deleted.
Luckily for me, Marco Carnazzo ran into the same problem and wrote a very useful Cordova hook to allow you to add specific configuration parameters for your iOS -Info.plist
and Android AndroidManifest.xml
.
How to use this hook
First, copy the hook: https://gist.github.com/marcocarnazzo/6f01a57d390e8fe3071f
Second, create a file named update_platform_config.js
under hooks/after_prepare
in your Cordova app folder.
Third, add the specific values in your Cordova config.xml as instructed in the hook code.
For example, in my case, I needed to add an array of available languages in my iOS app to allow it to translate properly the camera plugin texts.
So I just added this piece of code in my config.xml
under the '
<config-file platform="ios" target="*-Info.plist" parent="CFBundleLocalizations">
<array>
<string>fr</string>
<string>nl</string>
<string>it</string>
<string>es</string>
<string>de</string>
<string>en</string>
</array>
</config-file>
After building your ios app using cordova build ios
, if you look at the generated -Info.plist
file under paltforms/ios/$your_project_name
, you will be able to see your specific parameters in it ! For my example, it looks like that:
<key>CFBundleLocalizations</key>
<array>
<string>fr</string>
<string>nl</string>
<string>it</string>
<string>es</string>
<string>de</string>
<string>en</string>
</array>
And it works exactly the same for your AndroidManifest.xml
file! Neat isn't it?
Now you can finally stop worrying about forgetting to edit your config files every time you build your app!
I hope you enjoyed this article and found it useful. I’d love to hear about your thought about it in the comment section. Thanks for reading! And may code be with you.