ios - variable - xcode user-defined build settings in code

Use User-Defined build settings in custom.plist file (2)

I have different build configurations (Debug, Stage, Prod) defined for my app and I use User-Defined build settings:

to set up Facebook login and other stuff in Info.plist file:

In this scenario the $(USER_DEFINED_SETTINGS) notation does work.

When I tried to set up Google SignIn, which requires using additional .plist file (GoogleService-Info.plist), and I used User-Defined settings in the same way I do in the Info.plist file, it doesn't work.

How can I use User-Defined settings in custom .plist files? If I can't, how can I workaround this?

  1. Create a new folder (for example: GoogleServiceInfoPlists).

  2. Copy there all .plist files for each Configuration

for example:

  1. Add new Run Script Phase at last (Xcode: Target -> Build Phases -> "+" button).

  2. Use script below to copy .plist file for given environment to the build directory.




echo "Copying ${RESOURCE_PATH} to ${BUILD_APP_DIR}"
cp "${RESOURCE_PATH}" "${BUILD_APP_DIR}/GoogleService-Info.plist"

PS: You do not need to add the file to project. Just create a new folder in the main directory.

I put two files with the (same) name GoogleService-Info.plist into my project.

One is at the root and one is in a folder called 'staging', so as to avoid a naming conflict in the file system.

Including one in one target and the other in another makes it so that each target has a unique plist file with the correct name.