Last Updated: October 31, 2017
· logicoder

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:


#define FACEBOOK_APP_ID             @"00000000"
#define FACEBOOK_APP_URL            @"fb00000000"
#define FACEBOOK_APP_NAME           @"App Display Name - Test"
#define FACEBOOK_APP_SECRET         @"abcdef00000000"


#define FACEBOOK_APP_ID             @"00000001"
#define FACEBOOK_APP_URL            @"fb00000001"
#define FACEBOOK_APP_NAME           @"App Display Name"
#define FACEBOOK_APP_SECRET         @"abcdef00000001"


and set the keys<>values like:


Remember to Product > Clean when you change the defined values.

2 Responses
Add your response

It is useful. I never notice it can work in info.plist.

over 1 year ago ·

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

over 1 year ago ·