asgeo1
asgeo1

Reputation: 9078

Cordova - can you override plist NSPhotoLibraryUsageDescription values set by a plugin?

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:

  1. A plugin can provide a bad description (such as the cordova-plugin-x-socialsharing plugin), which Apple can reject you for

    You then have no way to override this that I can see.

  2. 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)

Upvotes: 3

Views: 872

Answers (1)

DaveAlden
DaveAlden

Reputation: 30356

You can use cordova-custom-config to override the usage description messages which have been inserted by Cordova: since cordova-custom-config applies its changes (by default) on Cordova's after_prepare hook, it will execute afterwards so its changes will take precedence.

Install it into your project:

cordova plugin add cordova-custom-config

Then define a <custom-config-file> block in your config.xml, for example:

<custom-config-file platform="ios" target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
    <string>My override description</string>
</custom-config-file>

Note: cordova-plugin-x-socialsharing does 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:

cordova plugin add cordova-plugin-x-socialsharing --variable PHOTO_LIBRARY_ADD_USAGE_DESCRIPTION="Some description" --variable PHOTO_LIBRARY_USAGE_DESCRIPTION="Some other description"

Upvotes: 1

Related Questions