Search code examples
iosnode.jsxcodecordovacordova-plugins

Add IOS capability programmatically in Cordova plugin


I have developed a plugin for Cordova IOS, for using App Groups.

The plugin needs to activate App Groups Capability under Targets -> Capabilities in XCode and select one of the App Groups.

If I activate it manually, it works well, but I would like to activate it programmatically, well in plugin.xml, or with a custom hook.

Somebody have achieved that?


Solution

  • Add the following to the plugin.xml file then remove and reinstall the plugin. The capability will still need to be added to the provisioning profile(s), but Xcode should resolve that automatically if you build using the GUI or use the -allowProvisioningUpdates flag with cordova build ios/xcodebuild.

    <platform name="ios">
        <config-file target="*.entitlements"
                parent="com.apple.security.application-groups">
                <array><string>group.com.example</string></array>
        </config-file>
        <config-file target="**/Entitlements-Debug.plist"
                parent="com.apple.security.application-groups">
                <array><string>group.com.example</string></array>
        </config-file>
        <config-file target="**/Entitlements-Release.plist"
                parent="com.apple.security.application-groups">
                <array><string>group.com.example</string></array>
        </config-file>
    </platform>