Edit app.entitlements file during build phase
Asked Answered
M

1

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)

Milson answered 5/4, 2017 at 12:55 Comment(2)
Did you find a solution to this?Personate
@Personate No. I had to get a different app.entitlements for each of my target :-(Milson
G
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
Gripper answered 22/8, 2018 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.