In my development I wish to hit a development URL when im testing but when the app is run on my iPhone, I want it to run on production URL. How do I get about setting this i
I prefer the #define
method as well. For those less familiar, those are pre-processor directives and are set even before the compiler gets hold of the code.
Environment variables
are set at runtime of the program, and can be manipulated in the scheme editor
of Xcode 4.x+. You could set up different schemes to hit different testing environments.
To access an environment variable at runtime from within your code, use the following:
NSString *url = @"http://standardurl.com";
NSDictionary *env = [[NSProcessInfo processInfo] environment];
NSString *overrideURL = [env valueForKey:@"url"];
if (overrideURL != nil)
url = overrideURL;