Xcode使用方案来确定开发/暂存/生产服务器URL [英] Xcode using schemes to determine dev/staging/production server URLs

查看:99
本文介绍了Xcode使用方案来确定开发/暂存/生产服务器URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用Xcode的方案来确定运行我的应用程序的服务器。我有一个从服务器获取其信息的应用程序。像大多数人一样,我有一个开发服务器,一个登台服务器和一个生产服务器。

I wish to use Xcode's schemes to determine what server to run my app against. I have an app that fetches its information from a server. Like most people I have a development server, a staging server and a production server.

我希望为每个人创建一个方案,其中Xcode将注入正确的URL。我是否复制了运行方案并添加了环境变量?这是最好的做事方式,我不特别希望在我的服务器类中使用#ifdef并在每次更改服务器时将其设置为代码。任何人都可以指出我正确的方向吗?

I wish to create a scheme for each of these where Xcode will inject the correct URL. Do I duplicate the run scheme and add environmental variables? Is this the best way to do things, I don't particularly wish to have #ifdef's in my server class and setting it in code each time I change server. Can anyone point me in the right direction please?

FYI:我正在使用Xcode 5.0.2 iOS7 SDK。

FYI: I'm using Xcode 5.0.2 iOS7 SDK.

每个人都提出了一些很好的建议,但我觉得@ redent84的答案最适合我的需要。虽然我觉得有趣的是没有人真正建议使用不同的方案。 [/编辑]

Everyone gave some great suggestions but I feel @redent84 answer best suits my needs. Though I found it interesting that none actually suggested using different schemes. [/EDIT]

推荐答案

我建议您创建不同的 XCode Targets 。我建议您更改应用程序的应用程序标识符,例如,生产应用程序将是 com.mycompany.App ,并且DEVEL版本将是 com.mycompany.App-DEVEL 。这样您就可以在HockeyApp或TestFlight中单独跟踪应用程序,并且您可以同时在同一设备中同时拥有这两个应用程序。

I recommend you to create different XCode Targets for each environment. I recommend you to change the App Identifier of the Apps, for example, the production app would be com.mycompany.App and the DEVEL version would be com.mycompany.App-DEVEL. This way you can track the Apps separately in HockeyApp or TestFlight, and you can have both applications in the same device at the same time.

然后,添加定义的预处理器宏每个目标的环境。例如, DEVEL 用于开发。

Then, add Preprocessor Macros that define the environment for every target. DEVEL for development, for example.

如果URL是硬编码的,只需添加 #ifdef 选择网址的说明:

If the URL is hardcoded, simply add a #ifdef instruction to choose the URL:

#ifdef DEVEL
#define ENDPOINT_URL @"http://develserver:8080/EndPoint"
#elif defined(STAGING)
#define ENDPOINT_URL @"http://stagingserver:8080/EndPoint"
#else
#define ENDPOINT_URL @"http://app.mycompany.com/EndPoint"
#endif

这种方式不易出错,分发开发版本,更易于维护,并允许您将自定义代码添加到不同版本。例如,您可能希望在登录屏幕中包含版本号或显示用于开发的警报对话框,但不包括分发版本。

This way is less error-prone to distribute a development version, easier to maintain and allows you to add custom code to different versions. For example, you may want to include the version number in the login screen or show alert dialogs for development, but not for distribution version.

这篇关于Xcode使用方案来确定开发/暂存/生产服务器URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆