问题描述
正确我正在开发一个具有两个设置Dev and Live的应用程序。有没有办法根据应用程序是实时的还是仍在开发中来区分应该使用哪些设置,或者我必须在它们上线之前更改整个设置文件。
Right I am developing an app that has two lots of settings Dev and Live. Is there a way to distinguish which lot of settings should be used based on whether the app is live or still in development or do I have to change the whole settings files before it goes live.
如果您不确定的地方只是问,我不知道该怎么做。
I was unsure on how to put this so if your not sure place just ask.
推荐答案
您要做的是根据您的构建配置定义预处理器宏。因此,如果您有一个名为dev的构建配置和一个名为live的构建配置,您将为dev和live定义一个不同的值。
What you want to do is define a Preprocessor Macro based on your build configuration. So if you have a build configuration called dev and one called live you would define a different value for dev and live.
要实现此功能,请进入Xcode中的应用程序构建设置并搜索预处理器宏。为每个构建目标添加一个宏。
To implement this go into your apps build settings in Xcode and search for "Preprocessor Macros". Add a macro for each build target.
对于开发者,您可以添加:
For dev you could add:
APP_CONFIG=0
对于直播你可以添加:
APP_CONFIG=1
然后在您的代码可以通过简单的if语句区分开发和实时构建配置:
Then in your code you are able to distinguish between dev and live build configurations by a simple if statement:
#if APP_CONFIG == 0
NSLog(@"This is the dev build.");
#else
NSLog(@"This is the live build.");
#endif
这篇关于适用于iPhone应用的设置包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!