Batch SDK v2 is a major release, which introduces breaking changes from 1.x. This guide describes how to update your application when using a previous version.
Upgrading the SDK version
⚠️ Batch SDK 2.0 now requires Xcode 15.3 and iOS 13.0 or higher.
To upgrade from v1 to v2, you need to change the SDK version according to your package manager:
Update by using the "update package" option from Xcode or updating your package.swift.
Update your Podfile as following and run pod update.
Podfile
pod 'Batch', '~>2.0'
Update your Cartfile if necessary and run carthage update Batch.
Cartfile
github "BatchLabs/Batch-iOS-SDK"~>2.0
Linking the SDK
Batch is now distributed as a dynamic framework. This mean you can now safely link Batch between multiple framework targets!
Since Batch is now a mergeable dynamic library, the additional metadata induced by this feature makes the XCFramework distribution heavier, but has no effect in the final size of Batch in your app once compiled.
Vision OS
This version introduced the visionOS support but some features are still unsupported like:
In-App messaging and mobile landings are unavailable.
In-App rating is not supported on visionOS due to an OS limitation.
Core migration
Renaming default module
This version introduced an important change since the default Batch module has been renamed into BatchSDK. This mean you have to replace all your calls to this module like when starting the SDK.
BatchSDK.start(withAPIKey: "YOUR_API_KEY")
[BatchSDK startWithAPIKey:@"MY_API_KEY"];
Advertising Identifier
The iOS Batch SDK 1.21 had removed automatic collection of IDFA (Identifier For Advertisers). This version has totally dropped the support of the IDFA and you can no longer set an advertising id to Batch since all related APIs have been removed.
Advanced Information
The Batch SDK V1 allowed you to disable advanced information generally with setUseAdvancedDeviceInformation(false). This has been removed and replaced with a more fine-tuning control of what you want to enable with:
BatchSDK.updateAutomaticDataCollection { config in
config.setGeoIPEnabled(true) // Enable GeoIP resolution on server side
config.setDeviceModelEnabled(true) // Enable automatic collection of the device model information
}
[BatchSDK updateAutomaticDataCollection:^(BatchDataCollectionConfig * _Nonnull config) {
[config setGeoIPEnabled:true]; // Enable GeoIP resolution on server side
[config setDeviceModelEnabled:true]; // Enable automatic collection of the device model information
}];
All data configurable with this API are now disabled by default and should be enabled if you want to use it.
All deprecated APIs in the SDK v1 have been removed. Some other APIs have been renamed/reworked to feel Swift native. To see in details the differences, please visit our changelog.
Project migration
This version follows Batch's pivot to being an omnichannel platform. It allows you to collect data for your Projects and Profiles. If you are not familiar with these two concepts, please see this guide beforehand.
Profile Attributes
First of all, most of the user-related write APIs have been removed. Reading methods are still usable since we do not provide yet a way to get synced data for a Profile, but keep in mind that the data returned is only about your installation and not your Profile.
To interacts with our user-centered model, you should now use the BatchProfile module. Let's see a migration example.
BatchProfile.identify("john.doe")
BatchProfile.editor { editor in
try? editor.setLanguage("en")
try? editor.setRegion("US")
try? editor.setEmailAddress("[email protected]")
editor.setEmailMarketingSubscriptionState(BatchEmailSubscriptionState.subscribed)
try? editor.set(attribute: 26, forKey: "age")
try? editor.removeAttribute(key:"firstname")
try? editor.addToStringArray(item: "has_bought", forKey: "actions")
try? editor.removeFromStringArray(item: "has_bought", forKey: "actions")
try? editor.removeAttribute(key:"actions")
// Don't forget to use `editor.save()` if you use the editor in a local variable and not a closure like here.
}
[BatchProfile identify:@"john.doe"];
[BatchProfile editWithBlock:^(BatchProfileEditor * _Nonnull editor) {
[editor setLanguage:@"en" error:nil];
[editor setRegion:@"US" error:nil];
[editor setEmailAddress:@"[email protected]" error:nil];
[editor setEmailMarketingSubscriptionState:BatchEmailSubscriptionStateSubscribed];
[editor setIntegerAttribute:26 forKey:@"age" error:nil];
[editor removeAttributeForKey:@"firstname" error:nil];
[editor addItemToStringArrayAttribute:@"has_bought" forKey:@"has_bought" error:nil];
[editor removeItemFromStringArrayAttribute:@"has_bought" forKey:@"has_bought" error:nil];
[editor removeAttributeForKey:@"actions" error:nil];
// Don't forget to use `[editor save]' if you use the editor in a local variable and not a closure like here.
}];
For more information, please see the following sections :
To make it easier to collect data to a Profile, Batch has added two automatic ways to migrate old installation's data on a Profile. So the first time a user will launch your application running on v2 :
He will be automatically identified (logged-in) if he had a Batch custom_user_id set on the local storage.
Its natives (language/region) and customs data will be automatically migrate to a Profile if your app is attached to a Project.
These migrations are enabled by default, but you may want to disable them, to do so add the following before starting the SDK:
import Batch
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Disable profile's migration
BatchSDK.setDisabledMigrations([
// Whether Batch should automatically identify logged-in user when running the SDK for the first time.
// This mean user with a custom_user_id will be automatically attached a to a Profile and could be targeted within a Project scope.
.customID,
// Whether Batch should automatically attach current installation's data (language/region/customDataAttributes...)
// to the User's Profile when running the SDK for the first time.
.customData
])
// Then start Batch SDK.
BatchSDK.start(withAPIKey: "YOUR_API_KEY")
}
@import Batch;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Disable profile's migration
[BatchSDK setDisabledMigrations:
// Whether Batch should automatically identify logged-in user when running the SDK for the first time.
// This mean user with a custom_user_id will be automatically attached a to a Profile and could be targeted within a Project scope.
BatchMigrationCustomID |
// Whether Batch should automatically attach current installation's data (language/region/customDataAttributes...)
// to the User's Profile when running the SDK for the first time.
BatchMigrationCustomData
];
// Then start Batch SDK.
[BatchSDK startWithAPIKey:@"MY_API_KEY"];
return YES;
}