I build an app to receive FCM push notifications
. It is received notifications perfectly. Working in foreground it is ok.
But when app is in background and any other app is not open
, when clicking the push notification, app comes to foreground, But our app is background and another app is foreground
, even if it is received a push notification and I clicked it, app doesn’t come to foreground.
But all the functionalities are works fine to click action. This is my code. Please look at it?
pushObject.on('notification').subscribe((data: any) => {
console.log('data -> ', data);
//if user using app and push notification comes
if (data.additionalData.foreground) {
// if application open, show popup
let confirmAlert = this.alertCtrl.create({
title: data.title,
subTitle: data.message,
enableBackdropDismiss: false,
buttons: [{
text: 'View',
handler: () => {
//TODO: Your logic here
let navTransition = confirmAlert.dismiss();
navTransition.then(() => {
if (data.titleHire == "Confirmed") {
this.navCtrl.push(ThirdPage, {
hireNo: data.additionalData['subtitle']
});
}
else if (data.title == "Rejected") {
this.navCtrl.push(ForthPage, {
hireNo: data.additionalData['subtitle']
});
}
else if (data.title == "Hire") {
console.log("view-confirmed-hires");
this.navCtrl.push(ViewConfirmedHiresPage);
}
console.log('Push notification received');
});
return true;
}
}]
});
confirmAlert.present();
} else {
//if user NOT using app and push notification comes
//TODO: Your logic on click of push notification directly
if (data.title == "Confirmed") {
this.backgroundMode.moveToForeground();
this.navCtrl.push(ThirdPage, {
hireNo: data.additionalData['subtitle']
});
}
else if (data.title == "Rejected") {
this.backgroundMode.moveToForeground();
this.navCtrl.push(ForthPage, {
hireNo: data.additionalData['subtitle']
});
}
else if (data.title == "View") {
this.backgroundMode.moveToForeground();
console.log("view-confirmed-hires");
this.navCtrl.push(ViewConfirmedHiresPage);
}
console.log('Push notification clicked');
}
});