Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use User-Defined build settings in custom .plist file

I have different build configurations (Debug, 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 $(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?

like image 785
KlimczakM Avatar asked Dec 03 '15 13:12

KlimczakM


People also ask

How do I change my build settings in Xcode?

Choose the project in the Project Navigator on the left. Select the Configurations target from the Targets section and click the Build Settings tab at the top. The Build Settings tab shows the build settings for the Configurations target. It's possible to expand this list with build settings that you define.

How do I add a user defined variable in Xcode?

Select your project or target from the left side of the editor. Click the Build Settings button at the top of the editor. Click the Add Build Setting button at the bottom of the editor and choose Add User-Defined Setting.

How create plist file in iOS?

To create a plist file, it just as simple as creating a new class. Click menu File > New > File... ( ⌘ - CMD + N ).)


1 Answers

It's NOT possible to use User-Defined settings in custom .plist file.

BUT you can copy your custom .plist file to the right place when building the app:

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

  2. Copy there all .plist files for build configuration. For example:

  3. GoogleService-Info-Debug.plist

  4. GoogleService-Info-Stage.plist

  5. GoogleService-Info-Prod.plist

  6. Add new Run Script Phase - Xcode: Target-->Build Phases-->"+" button (top left corner).

  7. Use the script below to copy (replace) .plist file for given build configuration to the project directory:

    cp "${SRCROOT}/${PRODUCT_NAME}/Resources/GoogleServiceInfoPlists/GoogleService-Info-$CONFIGURATION.plist" "${SRCROOT}/${PRODUCT_NAME}/GoogleService-Info.plist" 
  8. Under Output Files, you should possibly also enter the target file in order to ensure the next phase begins only if the file was actually copied.

    "${SRCROOT}/${PRODUCT_NAME}/GoogleService-Info.plist" 
  9. Important: move newly added script before Copy Bundle Resources phase, or it will use the default file, ignoring replaced file.

Used variables/paths:

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

${PRODUCT_NAME} - predefined, product name.

$CONFIGURATION - predefined, it's your build configuration. By default, it is: Debug, Release. In my case: Debug, Stage, Prod. You can change build configurations in Xcode: Project (not Target!)-->Info.

Note:

GoogleService-Info.plist file must be added to the Xcode project resources (Build Phases-->Copy Bundle Resources) while Resources/GoogleServiceInfoPlists/GoogleService-Info-* files not necessarily.

If the above doesn't work try clicking in your disired .plist file > File Inspector > Target Membership > Check your main project so it can be bundled together in final output.

like image 63
KlimczakM Avatar answered Sep 21 '22 12:09

KlimczakM