I connected firebase cloud messaging to my flutter app, i am receiving push notifications successfully, but then i connected my flutter app to a custom backend connected to firebase cloud messaging and i am only receiving messages in foreground, not in background. Can anyone suggest any possible reasons for this issue ?
Here is my response structure:
`
{
message: {
token: device_token,
notification: {
title: params[:title],
body: params[:body],
},
data: params[:data],
webpush: {
notification: {
title: params[:title],
body: params[:title],
click_action: params[:click_action],
actions: params[:web_actions]
}
},
android: {
notification: {
click_action: params[:click_action],
title: params[:title],
body: params[:body],
}
},
apns: {
payload: {
aps: {
category: "NEW_MESSAGE_CATEGORY"
}
}
}
}
}
`
Here is my functions in Flutter to receive messages from FCM:
`FirebaseMessaging.onMessage.listen((RemoteMessage message) {
// dispatcher.enableAndMakeCanvasVisible();
print('Got a message whilst in the foreground!');
logMessage(message);
print('Notification not null');
String url = message.data['path'];
print(url);
GoRouter.of(context).go(url);
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
// dispatcher.enableAndMakeCanvasVisible();
print('Got a message onMessageOpenedApp!');
logMessage(message);
print('Notification not null');
String url = message.data['path'];
print(message.data);
print(url);
GoRouter.of(context).go(url);
});
`
I tried to imitate the response i.e. RemoteMessage from Firebase console, but they appear to me mostly same except message.notification?.android?.tag
which is campaign_collapse_key_6393197284280654770
from FCM, but null in my server, response, i.e. RemoteMessage.