TLDR; With Cordova, is there a way to overwrite any Info.plist values such as NSPhotoLibraryAddUsageDescription that a plugin may have set? (i.e. maybe with a hook?)
A lot of Cordova plugins attempt to configure plist values such as NSPhotoLibraryUsageDescription. For example:
<config-file target="*-Info.plist" parent="NSPhotoLibraryAddUsageDescription">
<string>Please authorize photo library to save pictures.</string>
</config-file>
<config-file target ="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
<string>Please authorize photo library to save pictures.</string>
</config-file>
If multiple plugins do this, we end up with multiple values in platforms/ios/ios.json, for example:
{
"prepare_queue": {
"installed": [],
"uninstalled": []
},
"config_munge": {
"files": {
"*-Info.plist": {
"parents": {
"NSPhotoLibraryUsageDescription": [
{
"xml": "<string>Send photos in your messages to the app.</string>",
"count": 1
},
{
"xml": "<string>We allow you to send us photos via our in-app messenger</string>",
"count": 144
}
],
...
This is problematic, as it seems that Cordova will only copy the value of the last item for any key (NSPhotoLibraryUsageDescription) into the Info.plist file.
Another issue is that setting these settings yourself in config.xml will not take precedence to the ones the plugin has set. It just depends which values are last in platforms/ios/ios.json.
So there are two problems here:
A plugin can provide a bad description (such as the
cordova-plugin-x-socialsharingplugin), which Apple can reject you forYou then have no way to override this that I can see.
If multiple plugins provide a value for the same Info.plist value, only the last one is used. That is a problem to me, as you can't really control which is the "last" one.
So my question is - Is there a way in config.xml or a hook, to provide the actual Info.plist settings that will be used?
(I'm currently using Cordova CLI 8.1.2)
You can use cordova-custom-config to override the usage description messages which have been inserted by Cordova: since
cordova-custom-configapplies its changes (by default) on Cordova'safter_preparehook, it will execute afterwards so its changes will take precedence.Install it into your project:
Then define a
<custom-config-file>block in yourconfig.xml, for example:Note:
cordova-plugin-x-socialsharingdoes provide a mechanism to override its own default descriptions - it defines<preference>s which can be overriden using a variable during plugin installation, for example: