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, so you have to handle this in the other way.
Although, you can copy your custom .plist file to the right place:
Run Script Phase
(Xcode: Target->Build Phases->"+" button).Use script below to copy (replace) .plist file for given environment to the main directory (it's
src
in my case):${SRCROOT}
- predefined, it points to your project location.$CONFIGURATION
- predefined, it's your build configuration, in my case:Debug
,Stage
,Prod
. You can change this in Xcode: Project (not target!)->Info.Please note that
src/GoogleService-Info.plist
file must be added to the Xcode project (Build Phases->Copy Bundle Resources) while/src/Resources/GoogleServiceInfoPlists/GoogleService-Info-*
files not necessarily.UPDATE:
Remember that your new Run Script must be placed before Copy Bundle Resources build phase. Otherwise, it won't work because it would be copied too late and the default version of the .plist file would be used.
Create a new folder (for example:
GoogleServiceInfoPlists
).Copy there all
.plist
files for each Configurationfor example:
Add new
Run Script Phase
at last (Xcode: Target -> Build Phases -> "+" button).Use script below to copy
.plist
file for given environment to the build directory.script:
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.