iOS > Advanced

General

Batch Sample Apps

If you want to see a proper integration of the Batch SDK and to test any of its functionalities, you can take a look at our sample apps.

Download the sample app on GitHub

They are currently written for iOS in both Swift and Objective-C.

Manual SDK integration

Step 1.

First, download the SDK. Include Batch.embeddedframework in your project by dragging and dropping it into the left panel as shown here:

Left panel view

Step 2.

Be sure Batch.framework and libsqlite3.dylib are in the Build Phases of your application target:

Build phases

Step 3.

In order to avoid a link issue when building your application, add -ObjC to Other Linker Flags, under Build Settings of your application target.

If you cannot or do not want to use the -ObjC linker flag: Look for Other Linker Flags in the Build Settings of your application target. Add -force_load flag then drag and drop Batch.framework right under this flag and finally add /Batch at the end of the path. Force load

You can now proceed with the integration of the SDK.

Problems with your application delegate

If Batch tells you that it was unable to automatically integrate with your application delegate, it's probably because there is a conflict with another SDK.

Try calling [Batch setupWithAPIKey:] earlier in your application delegate.

Migration from BatchUserProfile

If you've previously used BatchUserProfile, you can easily use Batch User. You will still be able to set a custom region, language or identifier with the new API.

The main difference between Batch User and BatchUserProfile is that you'll now be required to use an editor object in order to make changes, and then save them. This transactional behaviour brings additional thread-safety and better performance.

That way, what used to be:

BatchUserProfile *userProfile = [Batch defaultUserProfile];
if (userProfile) {
    // Use the user profile to set custom language and data 
    userProfile.language = @"en"; // Language must be 2 chars, lowercase, ISO 639 formatted
    userProfile.region = @"US"; // Region must be 2 chars, uppercase, ISO 3166 formatted
    userProfile.customIdentifier = @"john.doe@gmail.com";
}
let userProfile = Batch.defaultUserProfile()
if let _userProfile = userProfile {
    // Use the user profile to set custom language and data 
    _userProfile.language = "en" // Language must be 2 chars, lowercase, ISO 639 formatted
    _userProfile.region = "US" // Region must be 2 chars, uppercase, ISO 3166 formatted
    _userProfile.customIdentifier = "john.doe@gmail.com"
}

Will become this:

BatchUserDataEditor *editor = [BatchUser editor];
[editor setLanguage:@"en"]; // Language must be 2 chars, lowercase, ISO 639 formatted
[editor setRegion:@"US"]; // Region must be 2 chars, uppercase, ISO 3166 formatted
[editor setIdentifier:@"john.doe@gmail.com"];
[editor save];
let editor = BatchUser.editor()
editor.setLanguage("en") // Language must be 2 chars, lowercase, ISO 639 formatted
editor.setRegion("US") // Region must be 2 chars, uppercase, ISO 3166 formatted
editor.setIdentifier("john.doe@gmail.com")
editor.save()

BatchUserProfile is now deprecated, but will continue to work. We still suggest you migrate in the near future, so you can take advantage of the new capabilities.