如何在XCode中配置独立的运行时设置集 [英] How to configure independent sets of runtime settings in XCode

查看:169
本文介绍了如何在XCode中配置独立的运行时设置集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPhone应用程式连线至三个不同的伺服器,例如生产暂存测试。有一些配置值,应用程序使用它取决于它连接到哪个服务器,例如。 Facebook App ID,TestFlight小组密钥等。



我希望在GIT中拥有所有设置,只选择应用程序在编译或释放时应使用的配置。例如,选择测试时,XCode中的产品 - >运行会运行连接到测试产品 - >存档使用也连接到测试的发布版本创建IPA文件。



我不想创建比调试和发布更多的构建配置(因为这意味着构建配置/运行时配置的6种不同的组合)。我认为理想的解决方案是,我有三种方案:生产测试分期,每个方案选择一个三个Info.plist文件与应用程序一起使用。这将允许我不仅定义不同的运行时设置,而且还根据后端服务器定义不同的应用程序版本或软件包标识符。但它看起来不像我可以配置存档操作以任何其他方式,除了选择不同的构建配置。

编辑:为了更清楚一些,生产/分期/测试是后端服务器,而不是iOS应用程序的版本。 iOS应用程序有两个版本: debug / release 。换句话说,我可能想要运行连接到生产服务器的应用程序的调试版本,例如调试从该服务器返回的JSON导致的崩溃。

解决方案

我建议使用不同的构建目标为每个环境。我成功地使用了这个模型之前。在项目的设置中,您可以复制当前目标,并根据需要更改构建设置。有一个 Info.plist文件属性,将允许您更改该目标的默认plist。



之后,您可以为将使用相应目标的每个环境创建一个方案。



您可以更进一步,为每个目标和不同的名称使用不同的bundle id。这将允许您在同一设备上同时安装暂存和生产版本。



这样做的唯一缺点是,当您要更新配置文件时,您有更多的工作。


My iPhone application connects to three different servers, say: production, staging and testing. There is a bunch of configuration values that the application uses depending on to which server it connects to, e.g. Facebook App ID, TestFlight team key, etc.

I'd like to have all the settings in GIT and only select which configuration the application supposed to use when compiling or releasing. For example, when testing is selected, Product -> Run in XCode runs the debug version of the app connecting to testing, and Product -> Archive creates the IPA file with the release version that also connects to testing.

I don't want to create more build configurations than debug and release (because that would mean 6 different combinations of build configurations/run-time configurations). The ideal solution, as I see it, would be that I have three schemes: production, testing and staging, and each scheme selects one of three Info.plist files to use with the application. That would allow me to not only define different run-time settings, but also different application versions or bundle identifiers depending on the back-end server. But it doesn't look like I can configure the Archive action in any other way apart from selecting a different build configuration. Any ideas if that could be achieved in any way?

Edit: To make it a bit more clear, production/staging/testing is the back-end server, not the version of the iOS application. The iOS app comes in two versions: debug/release. In other words I may want to run a debug version of the application connecting to the production server for example to debug a crash caused by JSON returned from that server. I could have named the servers as A, B and C for the sake of clarity.

解决方案

I would suggest using different build targets for each environment. I successfully used this model before. In your project's settings you can duplicate the current target and change the build settings as needed. There's an Info.plist File property that will let you change the default plist for that target.

After that, you can create a scheme for each environment that will use the according target.

You can get a step further and use different bundle id for each target and different names. That will allow you to install both the staging and the production builds on the same device for example.

The only downside in this is that you have more work when you want to update provisioning profiles.

这篇关于如何在XCode中配置独立的运行时设置集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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