6

I have several target in my Xcode project each of them having an associated domain but a different one.

Screenshot a the entitlements file

I'd like to have the same entitlements file for all my target and having a script with PListBuddy to change the value the domain.

I already have a script that works that I launch during the Build Phases that edit the file correctly :

case $TARGET_NAME in
  "EN6") fireBaseUrl="FOO.app.goo.gl";;
  "ES5") fireBaseUrl="BAR.app.goo.gl";;
  "SVT-C4") fireBaseUrl="FOOFOO.app.goo.gl";;
  "PC5") fireBaseUrl="BARBAR.app.goo.gl";;
  *) fireBaseUrl="FOOBAR.app.goo.gl";;
esac

# Universal links used by Firebase
associatedDomainKey="com.apple.developer.associated-domains"
/usr/libexec/PlistBuddy -c "delete ${associatedDomainKey}" app.entitlements
/usr/libexec/PlistBuddy -c "add :${associatedDomainKey} array" -c "add :${associatedDomainKey}:0 string applinks:${fireBaseUrl}" app.entitlements

The problem is that I have a "The executable was signed with invalid entitlements." error when installing the app on a device.

I guess it's because after being edited the entitlements file doesn't corresponds to the entitlements included in the provisioning profile anymore.

Do you know if there is a way to do what I want ? Using fastlane, shell script or anything... (I have 40 targets so I'd really like to get only one entitlements file for all of them)

mfaani
  • 33,269
  • 19
  • 164
  • 293
CedricSoubrie
  • 6,657
  • 2
  • 39
  • 44

1 Answers1

3

Xcode creates an .xcent with your entitlements before signing your app. You can add a Run Script phase as a last step to modify it using PlistBuddy, like this:

echo "Updating ${TARGET_TEMP_DIR}/${FULL_PRODUCT_NAME}.xcent"
/usr/libexec/PlistBuddy -c "add com.apple.developer.icloud-container-environment string Production" "${TARGET_TEMP_DIR}/${FULL_PRODUCT_NAME}.xcent" || exit 1
pfandrade
  • 2,359
  • 15
  • 25