Per configuration app group entitlement strings in Xcode?

EricS picture EricS · Aug 30, 2014 · Viewed 15.5k times · Source

Is there an easy way to have per-configuration app group entitlement strings in Xcode projects?

We're trying to share settings between an iOS application and today extension using an "app group" entitlement in both the targets.

The problem we're having is that we build the application with different bundle and team ids depending on whether it's an enterprise or a release build.

When I use Xcode 6's Capabilities screen, the app groups show up in red lettering and I don't see a way to change the strings for each configuration individually.

I assume one of the following will work, but I don't know which I should try first:

  1. .xcconfig files
  2. Manually created entitlement files
  3. Build script
  4. Configuration-dependent plist entries

Suggestions?

Answer

quellish picture quellish · Sep 9, 2014

You can use a different entitlements file for each configuration. This can be specified in the Xcode "Build Settings" user interface, or done through build configuration files (.xcconfig).

Example xcconfig:

CODE_SIGN_ENTITLEMENTS = Debug.entitlements

Where the value for CODE_SIGN_ENTITLEMENTS points to the correct entitlements file for this configuration. You can create as many configurations as you want in Xcode. By default Xcode creates Debug and Release, you may add Enterprise and use a build configuration file which points CODE_SIGN_ENTITLEMENTS to the correct entitlements file for Enterprise builds.

The Xcode "Capabilities" user interface will create and manage an entitlements file that is named after your build product. You can edit this file directly if you desire.

  1. Create an XCConfig build configuration file for each of your build configurations. For this example we will just use Debug and Release, it's simple to add your own build configurations such as Enterprise.
  2. As described above, populate the xcconfig files with the appropriate CODE_SIGN_ENTITLEMENTS settings.
  3. In the Project "Info" user interface, set the build configuration to use the appropriate XCConfig file:

enter image description here

  1. You can confirm by looking at the Code Signing Entitlements build setting for your build product. You should see something like this:

enter image description here

If you see bold text there, highlight that build setting and hit delete. This will remove the Xcode build setting that is overriding your xcconfig setting.