iOS,从代码中检测ad-hoc [英] iOS, detect ad-hoc from code

查看:228
本文介绍了iOS,从代码中检测ad-hoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在调试或进行临时部署时为我的iPhone应用程序使用不同的API网址。有没有办法从代码中检测(如果是adhoc)使用这个Url而不是默认的?

I want to use a different API url for my iPhone app when I'm debugging or doing an ad-hoc deployment. Is there any way to detect from code (if adhoc) use this Url rather than the default one?

推荐答案

有两种方法我能想到:

1。)有条件的编译

因为你必须将产品存档到分发adhoc构建,你也可以为Archive设置一个新配置并利用预处理器。

Since you have to "Archive" the product to distribute the adhoc build, you might as well setup a new config for Archive and leverage the preprocessor.

2。)基于Release / Debug / AdHoc的备用默认.settings文件。

2.) Alternate default .settings files based on Release/Debug/AdHoc.

与上面相同的建议,但使用.settings文件而不是编译。就个人而言,我推荐使用条件编译,因为如果你想在没有重新部署的情况下测试其他环境,可以在部署后更改(并保存)。

Same suggestion as above, but using a .settings file instead of compilation. Personally, I'd recommend this over the conditional compilation because it can be changed (and saved) after deployment if you want to test other environments without redeploying.

编辑

条件编译是指使用ifdef块对吗?我尝试了一次,但无法检查AD-HOC,只有DEBUG似乎工作

正确。

默认情况下没有定义ADHOC宏。但您可以轻松添加一个。

There is not an "ADHOC" macro defined by default. But you can easily add one.

以下是使用新的预处理器宏为ADHOC构建设置其他配置的方法:

Here's how you might go about setting up an additional configuration with a new preprocessor macro for your ADHOC builds:

第1步:设置一个新的配置(可选......你可能只是使用Release ...由你决定)。

Step 1: Setup a new Config (optional... you might just use Release... up to you).

第2步:为该配置添加预处理器宏。在我的屏幕截图中,它只显示Debug和Release,因为我实际上没有添加新的配置。如果你添加了一个新的配置(并称之为AdHoc,它也应该显示在这里:

Step 2: Add the preprocessor macro for that config. In my screenshot it only shows Debug and Release because I didn't actually add a new config. If you added a new Config (and called it something like "AdHoc", it should show up here as well:

添加 ADHOC = 1 就像调试配置的 DEBUG = 1 宏一样。

Add ADHOC=1 just like the DEBUG=1 macro for the debug config.

第3步:修改您当前的Scheme或复制它,以便Archive步骤使用您的新配置:

Step 3: Either modify your current Scheme, or duplicate it, such that the "Archive" step uses your new configuration:

这篇关于iOS,从代码中检测ad-hoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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