messagingBackgroundHandler function
Future<void>
messagingBackgroundHandler(
- Map pushedMessage,
- String platform
)
Implementation
@pragma('vm:entry-point')
Future<void> messagingBackgroundHandler(
Map<dynamic, dynamic> pushedMessage, String platform) async {
var methodChannel =
const MethodChannel('flutter_pushed_messaging', JSONMethodCodec());
await addLog(methodChannel, "$platform background message: $pushedMessage");
var token = await methodChannel.invokeMethod<String>('getToken');
var rawHandle = await methodChannel.invokeMethod<int>('getHandle');
await FlutterPushedMessagingPlatform.confirmDelivered(token ?? "",
pushedMessage["messageId"], platform, pushedMessage["mfTraceId"]);
var lastMessageId =
await methodChannel.invokeMethod<String>('getLastMessageId');
if (lastMessageId != pushedMessage["messageId"]) {
await addLog(methodChannel, "$platform processing message");
if (rawHandle != null && rawHandle != 0) {
final callbackHandle = CallbackHandle.fromRawHandle(rawHandle);
final onMessage = PluginUtilities.getCallbackFromHandle(callbackHandle);
if (onMessage != null) onMessage(pushedMessage);
}
await methodChannel.invokeMethod<bool>(
'setLastMessageId', {"lastMessageId": pushedMessage["messageId"]});
}
}