切换环境iOS

时间:2018-03-29 23:46:42

标签: ios xcode testflight test-environments

我需要在TestFlight内部测试时将应用程序指向开发服务器,并在推送到实际App Store时指向prod服务器。我有Debug&发布变量设置。归档应用程序时,构建配置将设置为“发布”。我想指出dev服务器,直到它通过iTunes-Connect推送到App Store。或者在推送到测试人员的TestFlight时将构建配置更改为Debug是正常的,并在推送到应用商店时更改回RELEASE?谢谢。

1 个答案:

答案 0 :(得分:3)

您可以使用方案

来实现这一目标

1)通过复制Release,在Project -> Info -> Configurations中创建新配置 enter image description here

我把它命名为Dev(发布) enter image description here

2)在Build Settings中为新配置设置适当的Provisioning配置文件(在您的情况下为adhoc或distribution)和Code Signing Identity enter image description here

3)为内部版本创建一个新方案, enter image description here enter image description here

4)将新方案的Archieve编辑为新的配置 enter image description here

5)到目前为止,我们处理了在内部测试/发布时指向dev服务器的用例。为此,我们必须创建一个新的编译器标志(Swift)/预处理器宏(Objective-C)。

<强>目标c

  Go to Build Settings -> Preprocessor Macros     

enter image description here

  Add a new macro "DEV_RELEASE=1" under the new configuration

enter image description here       注意:如果尚未在发布配置下设置,还要设置RELEASE = 1标志。

<强>夫特   转到构建设置 - &gt; Swift编译器 - 自定义标志    在Active Compilation Conditions下,将Flags RELEASE和DEV_RELEASE添加到适当的Release和Dev(Release)配置中。

enter image description here

6)现在您可以在代码中访问这些Macro / CompilerFlags

#ifdef DEBUG
   NSString* serverURL = @"https://dev.com”;
#elif RELEASE
   NSString* serverURL = @"https://prod.com”;
#elif DEV_RELEASE
   NSString* serverURL = @"https://dev.com”;
#endif

7)当你想发送一个内部Build(adhoc或Testflight)时,只需切换Scheme和Archieve enter image description here