Favicon

You are here: Home > App Distribution > Platforms > Apple > Exclude SDK from iOS Production Builds

Exclude SDK from iOS Production Builds

Learn how to exclude the Applivery SDK from your iOS production builds using Xcode configurations and compiler flags. Prevent app rejection from app stores.

5 min read

TL;DR

Exclude the Applivery SDK from your iOS production builds using Xcode configurations and compiler flags to avoid App Store rejection.

As you may already know, it’s not allowed to use the Applivery SDK in production Apps that are released in the official Apps Stores (Google Play and Apple App Store). In addition, it is a practice that we do not recommend, and that could cause the rejection of your App during the review process.

This tutorial will guide you through the process of conditionally excluding the Applivery SDK based on the Environment of the App (i.e., Live, Test, Staging, or Quality).

Note

For the purpose of this tutorial, we are considering that you already know the basics of how to manage different environments by using Schemas and Configurations. If not, we recommend taking a look at the following blog post.

1
Create Configuration Settings Files (.xcconfig) for Each of Your Environments

Go to File > New > File… (Command + N) -> Configuration Settings file and choose a descriptive name for your configuration file. For this example, we will create two different Configuration Files: one for the development environment (DEV.xcconfig) and another one for the production environment (PROD.xcconfig).

DEV.xcconfig

// App Info
APP_NAME = My Awesome App [DEV]
BUNDLE_IDENTIFIER = com.acme.awesome.dev

// Environment
ENVIRONMENT = DEV

// Applivery Options
APPLIVERY_TOKEN = b7C...2I6

PROD.xcconfig

// App Info
APP_NAME = My Awesome App [PROD]
BUNDLE_IDENTIFIER = com.acme.awesome.prod

// Environment
ENVIRONMENT = PROD

// Applivery Options
APPLIVERY_TOKEN = 1gxC...66f
EXCLUDED_SOURCE_FILE_NAMES = Applivery.framework

Since we do not want the Applivery SDK to be included in the Production Environment, we have added the following line of code EXCLUDED_SOURCE_FILE_NAMES = Applivery.framework that will exclude the source files of the Applivery SDK during the process of building the App.

Additionally, we will take advantage of this Configuration File to also define a different Applivery SDK Token for each of the environments.

2
Link the Configuration Files with Your Project Schemas

Now that we have multiple configuration files that describe the particularities of your Environments, it’s time to link them with your project Schemas. To do so, under your Project Configurations settings, select the appropriate Configuration File by using the Build Configurations dropdown menu.

ios-sdk-configurations-002 | Applivery
3
(Optional) Use Configuration File Variables in Your Code
ios-sdk-configurations-003 | Applivery

Additionally, to use the Info.plist Keys in your code, you can follow the next approach:

// Get values from Info.plist
public func InfoDictionary(_ key: String) -> String {
  guard let constant = Bundle.main.infoDictionary?[key] as? String else {
    return "CONSTANT NOT FOUND"
  }
  return constant
}

// Example of usage of the above function when starting the Applivery SDK
applivery.start(token:InfoDictionary("APPLIVERY_TOKEN"), appStoreRelease: false)
4
Conditionally use the SDK

Since the Import of the Applivery SDK has been excluded from the .xcconfig file when building the code, we recommend using Swift Compiler Custom Flags and Active Compilation Conditions to declare a set of constants that will help you conditionally start the Applivery SDK. Here is an example:

#if !APPSTORE
import Applivery
#endif

struct AppliveryWrapper {
   func setup() {
       #if !APPSTORE && !DEBUG
       let applivery = Applivery.shared
       applivery.logLevel = .info
       applivery.start(token:InfoDictionary("APPLIVERY_TOKEN"), appStoreRelease: false)
       #endif
   }
}
ios-sdk-configurations-004 | Applivery

Alternatively, if you do not want to use Configuration Files, you can exclude certain Source File Names under the Build Settings of your project for each of your Project Schemes.

Tip

Remember to thoroughly test your app in all environments to ensure the Applivery SDK is correctly excluded from production builds.

Key Takeaways

  • Use Xcode configuration files to manage different environments.
  • Exclude Applivery SDK from production builds to avoid App Store rejection.
  • Utilize compiler flags for conditional compilation of code.
  • Test your app thoroughly in all environments.