onBackgroundMessage does not appear.
gmbad opened this issue · comments
Hi!
On my xiaomi device I am not receiving notifications when my app is closed via onBackgroundMessage.
When the App is open, I normally receive notification via onMessage.
Can someone help me?
Follow my code:
cordova.plugins.firebase.messaging.requestPermission({forceShow: true});
// starting Android 8 we have to use a channel:
if (Number(device.version)>=8) {
cordova.plugins.firebase.messaging.listChannels().then(function(channels) {
var channel_txt = JSON.stringify(channels);
// if the channel does not exist yet, we have to create it:
if (channel_txt.indexOf('my_channel')<0) {
cordova.plugins.firebase.messaging.createChannel({
id: "1",
name: "Test Push",
importance: 4
});
}
});
}
cordova.plugins.firebase.messaging.onMessage(function(payload) {
alert("hello 1");
});
cordova.plugins.firebase.messaging.onBackgroundMessage(function(payload) {
alert("hello 2");
});
cordova.plugins.firebase.messaging.getToken().then(function(token) {
alert(token);
});
Thank you very much!
How are you sending your push notifications? I had the same problem and fixed it by changing my backend function (php) payload.
$fields = array
(
'registration_ids' => $registrationIds,
'notification' => $msg,
'soundname' => 'default',
);
i was using another plugin, after the switch to this one I changed the payload line from 'data' => $msg, to 'notification' => $msg
Hope it helps!
In the notification payload, are you passing the parameter content_available: true?
That fixed it for me.