4

My iOS App uses a specific server for production: http://mydomain.com/serverapi. While developing I would like to change this to http://localhost/serverapi. What is an elegant way to tell XCode to use the local URL by default.

Obviously it's very important, that a production release contains the production URL (Archiving in XCode.

Another use case would be to change the icon or app identifier while in development, to be able to tell the app apart from the version which might already be installed on the device.

2 Answers 2

6

I use macros for this (as Pablo suggested), but if you have a separate Info.plist file for different build configurations (as I do), then you could have a custom entry in your Info.plist and access it like so:

 [[[NSBundle mainBundle] infoDictionary] objectForKey:@"MyAppURL"]

However, macros are likely faster at runtime as they are compiled in. This is just another option.

Below is an image of the project setting.

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

How do you switch between those plists?
You can define which one is used for each configuration (RELEASE, DEBUG, etc.) in your project's target build settings, as Info.plist File.
For my purpose I now have two targets, which works fine for my purposes. Then I can generally use a specific plist file for each target.
4

You can use C language MACROS.

Like this:

#ifdef DEBUG
#define URL @"http://localhost/serverapi"
#else
#define URL @"http://mydomain.com/serverapi"
#endif

Then, in your code, you just use the defined constant:

NSLog(@"Hello, my current url is %@", URL);

2 Comments

Okay I'll try this one out. I guess I can define the DEBUG parameter in XCode's run profile settings.
can you spell out the steps more clearly for a newbie? Where do you define DEBUG? Is this a known build setting in XCode that's included, or could I call this "development" as well with the same results?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.