且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在iOS中,我们是否有类似Android上的Gradle Build Flavors之类的东西

更新时间:2023-11-28 23:51:52

您可以在Xcode中使用Schemes和Build配置。这是官方文档:



简而言之,过程为:


  1. 创建构建配置

  2. 设置一些自定义标志对于该配置。为此,转到目标,选择构建设置选项卡,然后搜索预处理器宏。在那里,您将能够添加自定义标志


  1. 编辑方案或创建新方案以使用您的构建配置。

  2. 在您的代码,则必须使用预处理器宏询问该标志是否可用:


#ifdef APP_STORE
//做点
#endif


In iOS do we have something like Gradle Build Flavors on Android.

Basically I want to integrate Applause SDK with my app but I dont want that code to be part of the release build. I only want to use applause sdk only to distribute the app internally and for bug reporting.

If there is nothing like flavors then what is the best way to do this.

You can make use of Schemes and Build configurations in Xcode. Here's the official documentation: https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/BasingBuildConfigurationsonConfigurationFiles.html

After you create a build configuration, you should edit your scheme to use that build configuration. For that click on your scheme and select Edit Scheme.

In short, the process is:

  1. Create a build configuration
  2. Set some custom flags for that configuration. For this, go to your target, select Build Settings tab, and search for Preprocessor Macros. There you'll be able to add custom flags

  1. Edit your scheme, or create a new scheme, to use your build configuration.
  2. In your code, you'll have to ask if the flag is available using preprocessor macros:

#ifdef APP_STORE //do something #endif