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?
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.
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.
To create a plist file, it just as simple as creating a new class. Click menu File > New > File... ( ⌘ - CMD + N ).)
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:
Create a new folder (for example: Resources/GoogleServiceInfoPlists
).
Copy there all .plist files for build configuration. For example:
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"
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With