Batch Actions is a module allowing you to register remotely-configurable runnable code to the SDK, when simple deeplinks wouldn't be enough. They can be triggered at any time by the SDK, allowing you to focus on the action code rather than when to trigger it.
Batch comes with builtin actions (deeplinking, user data edition, etc...)
An action has two components:
An identifier (case-unsensitive string), which will allow you to reference this action
While the identifier string is up to you, it cannot start with "batch.": these identifiers are reserved for built-in actions.
An implementation block
Registering them is easy, and should be done every time your app starts, right before starting Batch:
The source argument represents what caused the action to be triggered. You can use isKindOfClass (or a swift cast using as?) to check what source it comes from, and read what you need.
Two sources classes are currently used: BatchPushMessage and BatchManualUserActionSource. More will be added in the future.
Simply call the unregister method with the previously set identifier:
You might want to re-use the code you've already registered to Batch from your own code by triggering an action.
Simply give Batch the action identifier and arguments, and it will call your action:
Batch provide a set of pre-defined actions, allowing you to easily trigger a specific behavior without implementing them yourself.
batch.dismissSimply dismiss the notification and exit
Arguments
N/A
batch.deeplinkOpen the provided deeplink (will call the Deeplink Interceptor if one is set).
Arguments (required)
batch.ios_request_notificationsShow the notification permissions pop-up.
Arguments
N/A
batch.ios_redirect_settingsOpen the notifications settings of the current application.
Arguments
N/A
batch.ios_smart_reoptinChecks if the user has already been asked for notifications, if not it shows the notification permissions pop-up, otherwise it opens the notifications settings of the current application.
Arguments
N/A
batch.user.tagAdd or remove a tag associated with the current user.
Arguments (required)
batch.user.eventSend an event with associated tags and data.
Arguments (required)
batch.groupExecute a list of up to 10 nested actions successively.
Arguments (required)
batch.ios_tracking_consentOn iOS 14, asks for Tracking consent using the AppTrackingTransparency framework. If the user has already been asked and refused to consent, opens the app's settings where tracking can be enabled. Does nothing on iOS 13 and earlier, or if tracking has been restricted by the device's manager. Your application needs to have a 'NSUserTrackingUsageDescription' key in its Info.plist or else iOS will crash it. Available since Batch 1.16.
Arguments
N/A
batch.clipboardCopy a text to the device's clipboard.
Arguments (required)
batch.ratingOn iOS 10.3+, asks for the user to rate the app using SKStoreReviewController (this API's restrictions apply). Available since Batch 1.17.
Arguments
N/A
l
String - Required
The deeplink to open
E.g.{"l":"https://google.com"}
li
Boolean - Optional - Default false
If true the Batch SDK will try to open your deeplink inside the app
E.g.{"li":false}
a
String - Required
The action to perform.
Acceptable values are add and remove
E.g.{"a":"remove"}
c
String - Required
The collection to use when updating the tag
E.g.{"c":"actions"}
t
String - Required
The tag to update
E.g.{"t":"has_bought"}
e
String - Required
The name of the event to send
E.g.{"e":"my_awesome_event"}
l
String - Optional - default null
The label associated with the event
E.g.{"l":"label1"}
t
Array - Optional - default empty list
A list of tags to be send with the event
E.g.{"t":["tag1","tag2","tag3"]}
a
Object - Optional - default empty object
The data to send with the event
E.g.{"a":{"key":"value","key2":12,"key3":true}}
actions
Array - Required
A list of actions to perform. This list must not be longer than 10 elements and can't contains batch.group actions
E.g.{"actions":[["batch.deeplink",{"l":"https://google.com"}],["batch.user.tag",{"add":"..."}]]}
t
String - Required
The text to copy
E.g.{"t":"My awesome text !"}
BatchActions.register(BatchUserAction(identifier: "<YOUR_ACTION_NAME>",
actionBlock: { (identifier: String, arguments: [String : Any], source: BatchUserActionSource?) in
// Your action code here
}))BatchUserActionBlock alertActionBlock = ^(NSString * _Nonnull identifier, NSDictionary<NSString *,NSObject *> * _Nonnull arguments, id<BatchUserActionSource> _Nullable source) {
// Your action code here
};
[BatchActions registerAction:[BatchUserAction userActionWithIdentifier:@"<YOUR_ACTION_NAME>"
actionBlock:alertActionBlock]];BatchActions.unregister(actionIdentifier: "<YOUR_ACTION_NAME>")[BatchActions unregisterActionIdentifier:@"<YOUR_ACTION_NAME>"];BatchActions.perform(actionIdentifier: "alert", arguments: ["title": "Hello", "body": "How are you doing?"])[BatchActions performActionIdentifiedBy:@"alert" withArguments:@{@"title":@"Hello", @"body":@"How are you doing?"}];