Where to set environmental variables in iOS?

后端 未结 3 2050
旧巷少年郎
旧巷少年郎 2020-12-28 11:02

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

3条回答
  •  醉梦人生
    2020-12-28 11:23

    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;
    

提交回复
热议问题