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?
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:
Resources/GoogleServiceInfoPlists
).GoogleService-Info-Debug.plist
GoogleService-Info-Stage.plist
GoogleService-Info-Prod.plist
Add new Run Script Phase
- Xcode: Target-->Build Phases-->"+" button (top left corner).
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"
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.