Use #defined values in Info.plist
In Xcode go into Build Settings set Preprocess Info.plist File to YES and Info.plist Preprocessor Prefix File to a .h file you've placed in your project with #define directives.
I usually use a Constants.h file that's included by PrefixHeader.pch also and define Preprocessor Macros for DEVELOPMENT, TESTING and APPSTORE that I copy over to Info.plist Preprocessor Definitions.
For example, to use different Facebook app credentials in testing and in production, #define the values in your header like:
#ifdef DEVELOPMENT
#define FACEBOOK_APP_ID @"00000000"
#define FACEBOOK_APP_URL @"fb00000000"
#define FACEBOOK_APP_NAME @"App Display Name - Test"
#define FACEBOOK_APP_SECRET @"abcdef00000000"
#else
#define FACEBOOK_APP_ID @"00000001"
#define FACEBOOK_APP_URL @"fb00000001"
#define FACEBOOK_APP_NAME @"App Display Name"
#define FACEBOOK_APP_SECRET @"abcdef00000001"
#endif
and set the keys<>values like:
<key>FacebookAppID</key>
<string>FACEBOOK_APP_ID</string>
<key>FacebookDisplayName</key>
<string>FACEBOOK_APP_NAME</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>FACEBOOK_APP_URL</string>
</array>
</dict>
</array>
Remember to Product > Clean when you change the defined values.
Written by Marco Del Tongo
Related protips
2 Responses
It is useful. I never notice it can work in info.plist.
This saved many hours (our customer requieres 8 different builds, each one with slightly configuration changes)
One issue: your defines did not work in Xcode 9.0.1, had to remove the @ and the double quotes