iOS > SDK integration

Initial setup

Integrating the SDK

Native SDK

The iOS SDK is a complete standard static framework, compatible with iOS 8.0 and higher. It supports the following architectures: i386, x86_64, armv7, armv7s and arm64. Xcode 8 is required, but Batch will work with all Swift versions, along with Objective-C.

First, simply add this line to your Podfile to integrate Batch in your project:

pod 'Batch', '~> 1.10'

Then, run pod install in your Podfile folder, and open the .xcworkspace that was created. You're ready to go! In order to update Batch SDK, simply run pod update in that directory.

If you don't have a Podfile or are unsure on how to proceed, see the CocoaPods usage guide.

If you are coming from an older version of Batch and get compilation errors, you need to go to your Build Settings, search for Framework Search Paths and remove any line that is "$(PODS_ROOT)/Batch/**"

If you don't use CocoaPods, you can integrate Batch SDK manually.

Legacy SDK

Still using Xcode 7? You can install the last Batch version that supports Xcode 7 and iOS 6. Please note that they're not maintaned anymore, so features described by the documentation might not be available.

To get the legacy version, either change your Podfile line to

pod 'Batch', '1.5.4'`

or manually download the SDK from here

React Native

Using React Native? Batch works great in native iOS modules.

Your first start

Finally, implement the Batch startWithAPIKey: method in your AppDelegate application:didFinishLaunchingWithOptions: method:

@import Batch;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // Start Batch SDK.
  [Batch startWithAPIKey:@"MY_API_KEY"];

  return YES;
}
import Batch

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Batch.start(withAPIKey: "YOUR_API_KEY")
    [..]
}

YOUR_API_KEY is your Batch Dev or Live API key. You'll find the API keys needed to set up the SDK in ⚙ Settings → General:

  • Dev API key: Use it for development or testing purposes. This API key won't trigger stats computation. Please take care not to ship an app on a Store with this API key.
  • Live API key: Should be used in a production environment only and in the final version of your app on the Store.

These API keys must not be mistaken for the APNS environment Batch will output to the Xcode logs when starting. The environment depends on the app's provision, not on the Batch API Key used.

Testing your integration

Congratulations on finishing the bulk of the integration!

If you want to validate your implementation before proceeding with the Push setup, you can locate the log that Batch posts in the Xcode console.

[Batch] Batch started with a DEV API key

Batch also provides a simple debug tool that allows you to test your integration (⚙ Settings → Debug). It shows all the data available for a specific user ID.

Recommended
We recommend you print in your logs or display somewhere in your app the installation ID Batch automatically generates the first time you open the app. This will simplify the debug process.