iOS, detect ad-hoc from code

前端 未结 1 1001
北荒
北荒 2020-12-13 07:21

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 th

相关标签:
1条回答
  • 2020-12-13 07:37

    There are two ways I can think of:

    1.) Conditional Compilation

    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.) Alternate default .settings files based on Release/Debug/AdHoc.

    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.

    EDIT

    Conditional Compilation refers to using "ifdef" blocks right? I tried this once but couldn't get it to check for AD-HOC, only DEBUG seemed to work

    Correct.

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

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

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

    Setup a new config

    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:

    enter image description here

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

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

    enter image description here

    0 讨论(0)
提交回复
热议问题