I wish to use Xcode\'s schemes to determine what server to run my app against. I have an app that fetches its information from a server. Like most people I have a development se
I recommend you to create different XCode Targets for each environment. I recommend you to change the App Identifier of the Apps, for example, the production app would be com.mycompany.App
and the DEVEL version would be com.mycompany.App-DEVEL
. This way you can track the Apps separately in HockeyApp or TestFlight, and you can have both applications in the same device at the same time.
Then, add Preprocessor Macros that define the environment for every target. DEVEL
for development, for example.
If the URL is hardcoded, simply add a #ifdef
instruction to choose the URL:
#ifdef DEVEL
#define ENDPOINT_URL @"http://develserver:8080/EndPoint"
#elif defined(STAGING)
#define ENDPOINT_URL @"http://stagingserver:8080/EndPoint"
#else
#define ENDPOINT_URL @"http://app.mycompany.com/EndPoint"
#endif
This way is less error-prone to distribute a development version, easier to maintain and allows you to add custom code to different versions. For example, you may want to include the version number in the login screen or show alert dialogs for development, but not for distribution version.
Use a key in the plist (for each schema, eg: URL_TO_USE), use define to create a 'shortcut' to get the value.
#define MyURL [[NSBundle mainBundle] objectForInfoDictionaryKey:@"URL_TO_USE"]
EDIT
You must have multiple targets. Each target should point to a different .plist file. See: How to configure independent sets of runtime settings in XCode
I handle this by setting custom pre-processor defines for each scheme.