I have issue with fcm and local-notification.
fcm is consuming local notification on click but the problem is all the time it’s not fetching data only sometimes it’s picking up the data what should i do make both work??
I have issue with fcm and local-notification.
fcm is consuming local notification on click but the problem is all the time it’s not fetching data only sometimes it’s picking up the data what should i do make both work??
Can you clarify the issue with an example of the issue? Also, please provide a snippet of your code where the actions are triggered for fcm notifications. I’m not the most active on here,but I will try to remember to look back.
see the code below
for receiving notification action
this.fcm.onNotification().subscribe(data => {
console.log(data);
if(data.data==undefined){
if (data.wasTapped) {
if (data.page == 'offers') {
this.userDataProvider.tabSelectedIndex = 0;
} else if (data.page == 'rewards') {
this.userDataProvider.tabSelectedIndex = 2;
} else if (data.page == 'settings') {
this.userDataProvider.tabSelectedIndex = 3;
}
}
else {
console.log("Received in foreground=" + JSON.stringify(data));
if(this.platform.is('ios')){
let alert1 = this.alertCtrl.create({
title: data.title,
subTitle: data.body,
buttons: [{
text: 'OK',
role: 'cancel',
handler: () => {
alert1.dismiss();
}
}]
});
alert1.present();
}else{
var notificationDataFromFcm=null;
if(data.page!=undefined&&data.page!=null){
notificationDataFromFcm=data.page;
}
// Schedule a single notification
this.localNotifications.schedule({
id: 1,
title:data.title,
text: data.body,
launch:true,
data:notificationDataFromFcm
});
}
};
}
else{
if (data.wasTapped) {
var notificationData=JSON.parse(data.data);
if(notificationData.notificationSentThrough==='geofence'){
this.OffersCommonDataProvider.userClickedOnNotification = true;
this.OffersCommonDataProvider.userClickedOnGeofence = true;
this.OffersCommonDataProvider.userClickedCurrentGeofenceId = notificationData.geofenceNotificationData.id;
}
else if(notificationData.notificationSentThrough==='beacon'){
console.log(notificationData.regionData);
this.OffersCommonDataProvider.userClickedOnNotification = true;
this.OffersCommonDataProvider.userClickedOnBeacon = true;
this.OffersCommonDataProvider.userClickedBeaconDetails = notificationData.regionData;
console.log(this.OffersCommonDataProvider.userClickedBeaconDetails);
}
}
}
});
Below code is sending local notification
cordova.plugins.notification.local.schedule({
id:geofenceNumberIdOfNotification,
title:'You have offers at '+dataOfVerify.locationName,
text:"Tap to view the offers.",
data:{"notificationSentThrough":"geofence","geofenceNotificationData":data[0].notification},
foreground:true
});
When ever I click on any notification above fcm on subscribe gonna be trigger even for local notification too. In general the action should be received by local notification plugin.
I can handle in fcm only but the problem is sometimes fcm not picking that also properly
I got the same problem on iOS. Android is fine.
Didi you managed to solve this?
@rafaeldatalan
I updated both plugins now it’s working fine…
cordova plugin add cordova-plugin-fcm-with-dependency-updated-apns
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git