Initial setup

Integrating the SDK

Native SDK

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

Integrating with Swift Package Manager

Use Xcode's Swift Package Manager wizard to add

https://github.com/BatchLabs/Batch-iOS-SDK.git
Integrating with CocoaPods

CocoaPods 1.10 required

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

pod 'Batch', '~> 1.20'

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.

XCFramework distribution is supported since Batch 1.18.0 and Carthage 0.38.

Your first start

Implement the Batch startWithAPIKey: method in your AppDelegate application:didFinishLaunchingWithOptions: method:

If you're making a SwiftUI app, you will need to add a delegate first.

  • Swift
  • Objective-C
  • Swift UI
import Batch

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: 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.