Initial setup

Integrating the SDK

Native SDK

The iOS SDK is a complete standard static xcframework, compatible with iOS 10.0 and higher.
It supports the following architectures: i386, x86_64, armv7, arm64 (both for iOS, and iOS Simulator on Apple Silicon) and arm64e. Catalyst is supported.
Xcode 12.0+ is required, but Batch will work with all Swift versions, along with Objective-C.

Integrating with CocoaPods

CocoaPods 1.10 required

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

pod 'Batch', '~> 1.17'

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 don't use CocoaPods, you can integrate Batch SDK manually.

Integrating with Carthage

Batch is only available on Carthage 0.30 and higher

Simply add this line to your Cartfile to integrate Batch in your project:

github "BatchLabs/Batch-iOS-SDK"

Do not add Batch to the "carthage copy-frameworks" script input/output.

Note: Due to a limitation of the package manager, XCFramework distribution is not yet available via Carthage, which makes iOS Simulator on Apple Silicon and Mac Catalyst support unavailable.

Integrating with Swift Package Manager

Requires Xcode 12.5

Swift Package Manager support is currently in beta

Use Xcode's Swift Package Manager wizard to add

Note: While adding Batch using SPM will work with Xcode 12.4 and lower, your application will not be submittable to the App Store due to a known Xcode bug. See Xcode's 12.4 release notes for more info, or update to Xcode 12.5.

Your first start

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

  • Objective-C
  • Swift
@import Batch;

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

  return YES;

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.