I have a application which has push notification functionality and i am receiving notification successfully in both android and ios using cordova-plugin-fcm.
this is my code where i receive notification.
FCMPlugin.onNotification(
function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
this.handleNotification(data);
}else{
//Notification was received in foreground. Maybe the user needs to be notified.
alert("Notification received in foreground"); // this alert is generated
let alert1 = this.alertCtrl.create({ /// whereas this alert controller is not generated
title: 'You have got a new Notification.',
message: data.notificationDescription,
buttons: [
{
text: 'Ignore',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'View',
handler: () => {
this.handleNotification(data);
}
}
]
});
alert1.present();
}
},
function(msg){
console.log('onNotification callback successfully registered: ' + msg);
},
function(err){
console.log('Error registering onNotification callback: ' + err);
}
);
});
As you can see i have created a function which handles notification data after receiving notification if user wants to view that particular notification.
handleNotification(data){
alert("inside handle notification"); /// this alert is not being generated so it means it doesn't come to this function
if(data.isShowDetail){
alert("if data.isShowDetail is set");
}
else if(data.isRedirect){
else if(data.redirectScreen == 1){
//Home Page
this.nav.push(TabsPage);
}
else if(data.redirectScreen == 2) {
//news
this.nav.push(NewsPage);
}
}
else{
alert("inside last condition");
this.nav.push(NotificationPage);
}
}
What is the issue here or is there any other way to handle notification like the way i want?