iPhone-在本地和生产环境设置之间切换 [英] iPhone - Switching between local and production environment settings

查看:103
本文介绍了iPhone-在本地和生产环境设置之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,该应用程序在某处使用服务器来获取其数据.在应用程序源代码中的某处,我对用于连接的URL进行了硬编码.很好,除了我不总是要使用生产服务器进行测试!我不想弄乱实时数据,只是想在本地进行测试.因此,我为该服务器设置了本地版本.但是,要使iPhone应用程序使用该服务器,就是要更改源代码中的硬编码URL.

I am developing an iPhone app which uses a server somewhere to fetch its data. Somewhere in the app's source code I hardcoded the URL to use to connect to. This is fine, except that I don't always want to test using a production server! I don't want to mess with live data, just to test something locally. So I set up a local version of that same server. But in order to make the iPhone app use that server is to change the hardcoded URL in the source code.

如果您经常在两台服务器之间切换,那么这样做会有些麻烦.另外,我可能会不小心发布仍使用本地URL的应用程序!

This is a little bit of a pain in the ass to do if you're often switching between the two servers. Also, I might accidentally release the app which still uses the local URL!

我一直在想XCode可以帮我解决这个问题,因为它具有构建"Debug"和"Release"配置选项的概念.所以我的问题是:我可以以某种方式更改调试配置,使其指向本地服务器URL吗?可能通过指向包含环境特定URL的属性或plist文件来实现.然后,我可以制作此属性文件的两个版本,并将调试配置指向一个版本,而将发布配置指向另一个版本.

I was thinking that maybe XCode can help me with this since it has the notion of a "Debug" and a "Release" configuration option to build with. So my question is: can I somehow change the Debug configuration in a way that it points to local server URL? Maybe through pointing to a properties or plist file which contains the environment specific URL. I could then make two versions of this properties file and make the debug configuration point to one, while make the release configuration point to the other.

有人知道我该怎么做吗?

Does anyone know how I can accomplish this?

推荐答案

在您的一个头文件(例如预编译的头文件)中,使用URL定义宏.看看这篇文章和使用类似的方法.

In one of your header files (such as the pre-compiled header file) define macros with the URL. Take a look at this article and use a similar approach.

顺便说一句,我在所有应用程序中都使用了本文中的日志记录方法-它的工作原理很吸引人,我强烈推荐它!

Incidentally, I'm using the logging approach from this article in all my apps - it works like a charm, I strongly recommend it!

这篇关于iPhone-在本地和生产环境设置之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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