I am Using FCM in ionic 4 application.
I am using the below code to use generate push notification.
{
“to”:“hsagh_t2bvH0:APA91bHEkCghsw4tZa86mihDiHvdH71T0LbDtPwM-VP05nHW3di1_2XXbM7gNk08rYyokNcnexHLa3VExirA-Y6_fHB2pfPITws7j3oXethgfh78iG1U1WwB8rQ”,
“notification” : {
“body” : “New announcement assigned”,
“OrganizationId”:“2”,
“content_available” : true,
“priority” : “high”,
“subtitle”:“Elementary School”,
“Title”:“hello”
},
“data”: {
“title”: “TITLE”,
“body”: “MSG”,
“forceStart”: “1”
}
}
push notification comes only app is background, the other two states kill and foreground the push notification cannot appear please help me to solve this.
bump, same issue:
Ionic 4 app code:
this.fcm.onNotification().subscribe(data => {
console.log(data);
if (data.wasTapped) {
setTimeout(() => {
console.log('Received in background');
this.router.navigate(['incoming-order']);
}, 500);
} else {
console.log('Received in foreground');
this.router.navigate(['incoming-order']);
}
});
});
And the JSON format for sending the notification:
{
"to" : "--device_key_here--",
"collapse_key" : "type_a",
"priority":"high",
"notification" : {
"body" : "Delivery for 2 parcels nearby",
"title": "New Delivery Request",
"click_action": "FCM_PLUGIN_ACTIVITY"
},
"data" : {
"body" : "Delivery for 2 parcels nearby",
"title": "New Delivery Request",
"forceStart": "1"
}
}
Please if anyone has come across similar issues? doesn’t seem to be device specific testing on 2 different devices.
1 Like