Search code examples
cordovaplistphonegap-buildentitlementsphonegap

Editing the Entitlements.plist file using config.xml in Phonegap Build


I am trying to use the Apple Pay cordova plugin using Phonegap build. Here is my entry in the config file:

     <plugin name="cordova-plugin-applepay-stripe" source="npm">
<param name="STRIPE_TEST_PUBLISHABLE_KEY" value="xxxxxxxx" />
<param name="STRIPE_LIVE_PUBLISHABLE_KEY" value="xxxxxxxxx" />
<param name="APPLE_MERCHANT_IDENTIFIER" value="merchant.etc.etc" />
</plugin>

The plugin installs correctly however it will not work as I have not enabled the Apply Pay entitlement in Xcode as I am using a PC.

I am aware you can directly edit plist files from the phonegap build config.xml file like I have done here:

<gap:config-file platform="ios" parent="NSPhotoLibraryUsageDescription" overwrite="true">
<string>We are using the Photo Library for PayPal</string>...

So my question is how on earth do I edit the Entitlements.plist file so that I can enable ApplePay and add my merchant id?!

I have tried the following:

  <config-file platform="ios" target="*-Entitlements.plist" parent="com.apple.developer.in-app-payments">  
        <array>
            <string>merchant.etc.etc/string>
        </array>
</config-file>  

but that hasn't worked. Any help would be appreciated!


Solution

  • It seems like config-file only works in plugins for some reason. It seems like it should work in your project config.xml, but unfortunately it doesn't. However, you can use a local plugin to manage your entitlements to achieve more or less the same effect.

    For example, src/local-plugins/app-entitlements

    Add this to your config.xml

    <plugin name="app-entitlements" spec="src/local-plugins/app-entitlements" />
    

    You only need the src/local-plugins/app-entitlements/plugin.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <plugin id="app-entitlements" version="0.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0">
      <name>AppEntitlements</name>
      <platform name="ios">
        <config-file target="*-Debug.plist" parent="com.apple.developer.in-app-payments">
          <array>
            <string>YOUR DEBUG MERCHANT ID HERE</string>
          </array>
        </config-file>
        <config-file target="*-Release.plist" parent="com.apple.developer.in-app-payments">
          <array>
            <string>YOUR RELEASE MERCHANT ID HERE</string>
          </array>
        </config-file>
      </platform>
    </plugin>
    

    You can set other entitlements like push notifications or whatever you want here of course.

    Now when you do a fresh cordova platform add ios it should create Entitlements-*.plist with these keys and you should be good to go.

    Keep in mind, the "Capabilities" tab in Xcode is handled separately and is just a GUI helper. It won't reflect the entitlements for these files.