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

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

问题描述

我的 iPhone 应用程序连接到三个不同的服务器,例如:生产暂存测试.应用程序根据它连接到的服务器使用了一堆配置值,例如Facebook 应用 ID、TestFlight 团队密钥等

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.

我想在 GIT 中拥有所有设置,并且只选择应用程序在编译或发布时应该使用的配置.For example, when testing is selected, Product -> Run in Xcode runs the debug version of the app connecting to testing, and 产品 -> 存档 使用发布版本创建 IPA 文件,该文件也连接到测试.

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.

我不想创建比调试和发布更多的构建配置(因为这意味着构建配置/运行时配置的 6 种不同组合).在我看来,理想的解决方案是我有三个方案:生产测试暂存,每个方案选择其中一个三个 Info.plist 文件与应用程序一起使用.这将使我不仅可以定义不同的运行时设置,还可以根据后端服务器定义不同的应用程序版本或包标识符.但是,除了选择不同的构建配置之外,我似乎无法以任何其他方式配置存档操作.有什么想法可以以任何方式实现吗?

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?

编辑:为了更清楚一点,生产/暂存/测试是后端服务器,而不是 iOS 应用程序的版本.iOS 应用有两个版本:调试/发布.换句话说,我可能想要运行连接到生产服务器的应用程序的调试版本,例如调试由该服务器返回的 JSON 导致的崩溃.为清楚起见,我可以将服务器命名为 A、B 和 C.

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.

推荐答案

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

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.

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

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天全站免登陆