onMessageReceived method
Processes push notification received outside the CIO SDK. The method displays notification on device and tracks CIO metrics for push notification.
message
push payload received from FCM. The payload must contain data
payload received in push notification.
handleNotificationTrigger
flag to indicate whether it should display the
notification or not.
true
(default): The SDK will display the notification and track associated
metrics.
false
: The SDK will only process the notification to track metrics but
will not display any notification.
Returns a Future that resolves to boolean indicating if the notification
was handled by the SDK or not.
Implementation
@override
Future<bool> onMessageReceived(Map<String, dynamic> message,
{bool handleNotificationTrigger = true}) {
if (Platform.isIOS) {
/// Since push notifications on iOS work fine with multiple notification
/// SDKs, we don't need to process them on iOS for now.
/// Resolving future to true makes it easier for callers to avoid adding
/// unnecessary platform specific checks.
return Future.value(true);
}
try {
final arguments = {
TrackingConsts.message: message,
TrackingConsts.handleNotificationTrigger: handleNotificationTrigger,
};
return methodChannel
.invokeMethod(MethodConsts.onMessageReceived, arguments)
.then((handled) => handled == true);
} on PlatformException catch (exception) {
handleException(exception);
return Future.error(
exception.message ?? "Error handling push notification");
}
}