KlimczakM KlimczakM - 1 year ago 338
iOS Question

Use User-Defined build settings in custom .plist file

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

enter image description here

to set up Facebook login and other stuff in

Info.plist file

enter image description here

In this scenario the
notation does work. Then I tried to set up Google SignIn, which requires using additional
file (
), and I used User-Defined settings in the same way I had done in the
file but it doesn't work.

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

Answer Source

It's NOT possible to use User-Defined settings in custom .plist file, so you have to handle this in the other way.

This is what I've done to workaround this:

  1. Created a new folder (GoogleServiceInfoPlists).
  2. Copied there all .plist files for each environment (GoogleService-Info-Debug.plist, GoogleService-Info-Stage.plist and GoogleService-Info-Prod.plist).
  3. Added a new Run Script (Xcode: Target->Build Phases).
  4. Used this script to copy proper .plist file to the main directory (it's src in my case):

    cp "${SRCROOT}/src/Resources/GoogleServiceInfoPlists/GoogleService-Info-$CONFIGURATION.plist" "${SRCROOT}/src/GoogleService-Info.plist"

${SRCROOT} - it points to your project location.

$CONFIGURATION - it's your build configuration, in my case: Debug, Stage, Prod. You can change this in Xcode: Project (not target!)->Info.