Register the sdk callback event
- message:Returned event data
- message["event_name"]: event type
-
iOS/android:
- "onConnectStatus":callback for tcp connection status
- "onNotificationArrived": Notification delivery callback (iOS only triggers this event when notification is received in foreground)
- "onNotificationClicked":Notification click callback
- "onCustomMessage":Custom message callback
- "onTagMessage":callback for tag operation
- "onAliasMessage":Callback for alias operation
- "onInAppMessageShow": callback for inapp message arrival
- "onInAppMessageClick": callback for inapp message click
-
android Only:
- "onNotificationStatus":callback for application notification switch status, content type is boolean, true means open, false means closed
- "onNotificationDeleted":Notification deletion callback, the content is the notification message body
- "onPlatformToken":Manufacturer token message callback, the content is the manufacturer token message body
- "onNotificationUnShow":Callback for not displaying notification messages in the foreground (when the notification sent in the background is foreground information)
-
iOS Only:
- "checkNotificationAuthorization":Callback events to notify permission authorization status, callback event returned when iOS calls checkNotificationAuthorization method
- "onNotiInMessageShow": callback for noti inmessage arrival
- "onNotiInMessageClick": callback for noti inmessage click
- "onSetUserLanguage": callback for set user language, callback event returned when iOS calls setUserLanguage: method
- "onReceiveDeviceToken": callback for deviceToken
- "willPresentNotification":Callback for notification arrival, the content is the notification message body, recommend using onNotificationArrived instead
- "didReceiveNotificationResponse":Notification click callback, the content is the notification message body, recommend using onNotificationClicked instead, note that return fields need to be re-adapted
- "networkDidLogin":login successful, can use onConnectStatus instead, note that return fields need to be re-adapted
- "addTags": callback for addTags event, can use onTagMessage instead, note that return fields need to be re-adapted
- "setTags":callback for setTags event, can use onTagMessage instead, note that return fields need to be re-adapted
- "deleteTags":callback for deleteTags event, can use onTagMessage instead, note that return fields need to be re-adapted
- "cleanTags":callback for cleanTags event, can use onTagMessage instead, note that return fields need to be re-adapted
- "getAllTags":callback for getAllTags event, can use onTagMessage instead, note that return fields need to be re-adapted
- "validTag":callback for validTag event, can use onTagMessage instead, note that return fields need to be re-adapted
- "setAlias":callback for setAlias event, can use onAliasMessage instead, note that return fields need to be re-adapted
- "deleteAlias":callback for deleteAlias event, can use onAliasMessage instead, note that return fields need to be re-adapted
- "getAlias":callback for getAlias event, can use onAliasMessage instead, note that return fields need to be re-adapted
- "networkDidReceiveMessage":The callback of the custom message, the content is the message body of the custom message, can use onCustomMessage instead, note that return fields need to be re-adapted
-
- message["event_data"]: content, return value descriptions for each event are as follows:
- message["event_name"]: event type
-
onConnectStatus - Callback for tcp connection status
- Return value type: JSON object, containing the following fields:
- "enable": boolean - Connection status, true means connected, false means disconnected
- Return value type: JSON object, containing the following fields:
-
onNotificationArrived - Notification delivery callback
- Return value type: JSON object, containing the following fields:
- "messageId": string - Message ID
- "content": string - Notification content
- "title": string - Notification title
- "extras": object - Extended fields (key-value pairs)
- Return value type: JSON object, containing the following fields:
-
onNotificationClicked - Notification click callback
- Return value type: Same as onNotificationArrived, JSON object structure is the same
-
onCustomMessage - Custom message callback
- Return value type: JSON object, containing the following fields:
- "messageId": string - Message ID
- "content": string - Message content
- "title": string - Message title
- "extras": object - Extended fields (key-value pairs)
- Return value type: JSON object, containing the following fields:
-
onTagMessage - Callback for tag operation
- Return value type: JSON object, containing the following fields:
- "code": number - Operation result code, 0 means success
- "sequence": number - Request sequence number
- "tags": array - Tag array
- "queryTag": string - Query tag (only valid for query tag operation)
- "isBind": boolean - Whether the query tag is bound (only valid for query tag operation, true means bound, false means not bound)
- Return value type: JSON object, containing the following fields:
-
onAliasMessage - Callback for alias operation
- Return value type: JSON object, containing the following fields:
- "alias": string - Alias
- "code": number - Operation result code, 0 means success
- "sequence": number - Request sequence number
- Return value type: JSON object, containing the following fields:
-
onInAppMessageShow - Callback for inapp message arrival
- Return value type: JSON object, containing the following fields:
- "messageId": string - Message ID
- "target": string - Target identifier
- "content": string - Message content
- "clickAction": string - Click action
- "extras": object - Extended fields (key-value pairs)
- Return value type: JSON object, containing the following fields:
-
onInAppMessageClick - Callback for inapp message click
- Return value type: Same as onInAppMessageShow, JSON object structure is the same
-
onNotificationStatus - Callback for application notification switch status
- Return value type: JSON object, containing the following fields:
- "enable": boolean - Notification switch status, true means open, false means closed
- Return value type: JSON object, containing the following fields:
-
onNotificationDeleted - Notification deletion callback
- Return value type: JSON object, containing the following fields:
- "messageId": string - Message ID
- "content": string - Notification content
- "title": string - Notification title
- "extras": object - Extended fields (key-value pairs)
- Return value type: JSON object, containing the following fields:
-
onPlatformToken - Manufacturer token message callback
- Return value type: JSON object, containing the following fields:
- "platform": string - Platform identifier
- "token": string - Manufacturer token
- Return value type: JSON object, containing the following fields:
-
onNotificationUnShow - Callback for not displaying notification messages in the foreground
- Return value type: JSON object, containing the following fields:
- "messageId": string - Message ID
- "content": string - Notification content
- "title": string - Notification title
- "extras": object - Extended fields (key-value pairs)
- Return value type: JSON object, containing the following fields:
-
checkNotificationAuthorization - Callback events to notify permission authorization status
- Return value type: JSON object, containing the following fields:
- "enable": boolean - Authorization status, true means authorized, false means not authorized
- Return value type: JSON object, containing the following fields:
-
onNotiInMessageShow - Callback for noti inmessage arrival
- Return value type: JSON object, containing the following fields:
- "messageId": string - Message ID
- "content": string - Notification content
- "title": string - Notification title
- "extras": object - Extended fields (key-value pairs)
- Return value type: JSON object, containing the following fields:
-
onNotiInMessageClick - Callback for noti inmessage click
- Return value type: JSON object, containing the following fields:
- "messageId": string - Message ID
- "content": string - Notification content
- "title": string - Notification title
- "extras": object - Extended fields (key-value pairs)
- Return value type: JSON object, containing the following fields:
-
onSetUserLanguage - Callback for set user language
- Return value type: JSON object, containing the following fields:
- "code": number - Operation result code, 0 means success
- "error": string - Error message (exists when failed)
- Return value type: JSON object, containing the following fields:
-
onReceiveDeviceToken - Callback for deviceToken
- Return value type: JSON object, containing the following fields:
- "deviceToken": string - Device token string
- Return value type: JSON object, containing the following fields:
FlutterPluginEngagelab.addEventHandler(
onMTCommonReceiver: (Map<String, dynamic> message) async {
FlutterPluginEngagelab.printMy("flutter onMTCommonReceiver: $message");
String event_name = message["event_name"];
String event_data = message["event_data"];
});Set the appKey, called before initializing the function
FlutterPluginEngagelab.configAppKeyAndroid("appkey");Initialize sdk
if (Platform.isIOS) {
FlutterPluginEngagelab.initIos(
appKey: "your appkey",
channel: "testChannel",
);
} else if (Platform.isAndroid) {
FlutterPluginEngagelab.initAndroid();
}Set up the data center, called before the initialization function
FlutterPluginEngagelab.setSiteName("Singapore");Set User Language
FlutterPluginEngagelab.setUserLanguage("zh-Hans-CN");Set whether to turn on debug mode. When debug mode is turned on, a detailed log will be printed.
FlutterPluginEngagelab.configDebugMode(enable)- enable: Whether to turn on debugging mode, true means debugging mode, false does not
FlutterPluginEngagelab.configDebugMode(true);//Delete before publishingRegistrationID : Get the registrationId of the current device, which can be used for push
FlutterPluginEngagelab.getRegistrationId()Call this API to get the RegistrationID which returned by the Engagelab server only if the application is successfully registered, otherwise an empty string is returned.
FlutterPluginEngagelab.getRegistrationId().then((rid){
FlutterPluginEngagelab.printMy("flutter get registration id : $rid");
});Set whether iOS notifications are displayed in the foreground
FlutterPluginEngagelab.setUnShowAtTheForegroundIos(enable)- enable: true means not displaying, false means displaying
FlutterPluginEngagelab.setUnShowAtTheForegroundIos(true);Send a local notification
/** Correspondence between PRIORITY and IMPORTANCE
PRIORITY_MIN = -2corresponds toIMPORTANCE_MIN = 1;PRIORITY_LOW = -1corresponds toIMPORTANCE_LOW = 2;PRIORITY_DEFAULT = 0corresponds toIMPORTANCE_DEFAULT = 3;PRIORITY_HIGH = 1corresponds toIMPORTANCE_HIGH = 4;PRIORITY_MAX = 2corresponds toIMPORTANCE_MAX = 5; */
var fireDate = DateTime.fromMillisecondsSinceEpoch(
DateTime.now().millisecondsSinceEpoch + 3000);
var localNotification = LocalNotification(
id: 234,
title: 'fadsfa',
content: 'fdas',
fireTime: fireDate, // iOS only
subtitle: 'fasf', // iOS only
category: 'local', // Android only
priority: 2, // Android only
badge: 5, // iOS only
extra: {"fa": "0"});
FlutterPluginEngagelab.sendLocalNotification(localNotification)Enable or disable the device migration feature. When enabled, if a device model change is detected, the registration information will be automatically cleared and re-registered.
FlutterPluginEngagelab.setEnableResetOnDeviceChange(enable)- enable: true to enable, false to disable, default is false
// Enable device migration feature
FlutterPluginEngagelab.setEnableResetOnDeviceChange(true);
// Disable device migration feature (default state)
FlutterPluginEngagelab.setEnableResetOnDeviceChange(false);- This method should be called before initialization
- When device model changes (such as flashing, device replacement, etc.), local cached registration information will be automatically cleared
Set the application badge number with completion callback (iOS 5.2.0+)
FlutterPluginEngagelab.setBadge(badge)- badge: The badge number to set
Returns a Map containing:
- success: boolean - Whether the operation was successful
- error: string - Error message if operation failed
FlutterPluginEngagelab.setBadge(5).then((result) {
if (result['success']) {
FlutterPluginEngagelab.printMy("Badge set successfully");
} else {
FlutterPluginEngagelab.printMy("Failed to set badge: ${result['error']}");
}
});Set data collection control settings (Android 5.2.0+, aid parameter added in 5.3.0)
FlutterPluginEngagelab.setCollectControl({gaid: bool?, aid: bool?})- gaid: boolean? - Whether to enable GAID collection (optional)
- aid: boolean? - Whether to enable AndroidId collection (optional, added in 5.3.0)
// Set GAID collection
FlutterPluginEngagelab.setCollectControl(gaid: true);
// Set AndroidId collection (5.3.0+)
FlutterPluginEngagelab.setCollectControl(aid: true);
// Set both
FlutterPluginEngagelab.setCollectControl(gaid: true, aid: true);Set whether SDK is allowed to use UDP, UDP is allowed by default (Both iOS and Android)
FlutterPluginEngagelab.setEnableUdp(enable)- enable: boolean - true to allow UDP, false to disallow UDP
- This method must be called before SDK initialization
- Default is allowed (true)
// Allow UDP usage
FlutterPluginEngagelab.setEnableUdp(true);
// Disallow UDP usage
FlutterPluginEngagelab.setEnableUdp(false);Enable or disable push text to speech feature (Both iOS and Android)
FlutterPluginEngagelab.setEnablePushTextToSpeech(enable)- enable: boolean - true to enable, false to disable, default is false
- This method should be called before initialization
- Default is disabled
// Enable text to speech
FlutterPluginEngagelab.setEnablePushTextToSpeech(true);
// Disable text to speech
FlutterPluginEngagelab.setEnablePushTextToSpeech(false);Set appGroupId for sharing storage space between main app and notification service extension (iOS Only)
FlutterPluginEngagelab.setAppGroupId(appGroupId)- appGroupId: string - The appGroupId you configured for your bundle ID
- iOS only
- This method should be called before initialization
- The appGroupId must match the one set in notification service extension using mtpushSetAppGroupId: method
- Used to define shared storage space between main app and notification service extension for storing text to speech related resources
if (Platform.isIOS) {
FlutterPluginEngagelab.setAppGroupId("group.com.engagelab.push");
}To use this feature, you need to enable appGroups capability for your bundle ID. For steps to enable appGroups capability, please refer to iOS Certificate Setting Guide.
This feature supports iOS 14 and above.
Due to system limitations, the duration of text-to-speech playback is roughly consistent with the notification display time (approximately 10 seconds, with slight variations across different systems). When the notification disappears, the text-to-speech playback will also stop. Please control the duration of the speech accordingly.
You need to add a Notification Service Extension to your project and integrate Engagelab's Notification Service Extension SDK natively (please refer to iOS Integration Guide).
Then process the voice file in the Notification Service Extension according to the following sample code:
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
UNMutableNotificationContent *bestAttemptContent = [request.content mutableCopy];
// The appGroupId set by this method must match the appGroupId set in the project.
[MTNotificationExtensionService mtpushSetAppGroupId:@"xxx"];
// Set appkey
[MTNotificationExtensionService mtpushSetAppkey:@"Your appkey"];
// Process voice file
[MTNotificationExtensionService handleVoice:request with:^(NSString *soundName) {
if (soundName && soundName.length >= 0 ) {
// After the voice file is processed successfully, set the notification's sound to the processed voice file name
bestAttemptContent.sound = [UNNotificationSound soundNamed:soundName];
}
// Continue to call the push statistics reporting API
[MTNotificationExtensionService mtpushReceiveNotificationRequest:request with:^ {
NSLog(@"apns upload success");
self.contentHandler(bestAttemptContent);
}];
}];
}At the same time, you need to call the following two interfaces in Flutter to enable the text-to-speech feature.
FlutterPluginEngagelab.setEnablePushTextToSpeech(true);
FlutterPluginEngagelab.setAppGroupId("your appGroupId");You only need to call the following interface in Flutter to enable the text-to-speech feature.
FlutterPluginEngagelab.setEnablePushTextToSpeech(true);