search

Home  >  Q&A  >  body text

objective-c - Switching between development environment and release environment in iOS project to facilitate testing

The current requirement is: add a line to the settings list in the APP for cells dedicated to switching server environments for special accounts, so that you can freely switch between development, testing, and formal environments.

Currently, the global macro definitions are all written in the PCH file. I want to use NSUserDefault or Singleton to maintain the environment variable collection, but it has no effect. However, using Build Configuration to configure multiple environments, using xcconfig files to configure multiple environments, and using Targets to configure multiple environments, these methods will package multiple APPs and the configuration process is not simple. In fact, there should be a simpler way to implement a small function of switching between multiple environments. I hope interested students can answer this question.

三叔三叔2758 days ago1109

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-06-10 09:50:16

    Use NSUserDefault, and then define the macro APIHost to determine the value based on the NSUserDefault value

    #define ServerHost [[NSUserDefaults standardUserDefaults] objectForKey:@"xxxxx"]?releaseHost:debugHost

    reply
    0
  • Cancelreply