Closed erkanarslan closed 6 years ago
I solved the issue. I thought that onMessageReceivedCallback
is called when push message reaches the device. This is true if app is in foreground but not so when it is in background. When app is in background, this method is not called. It will be called when user taps the notification with the notification details like title, body, data, etc.. Also, message parameter passed to onMessageReceivedCallback
callback contains a foreground
property which shows if app is in background or foreground. It is a boolean.
I am having the same issue.
Foreground notifications works just fine, but after I tap on the notification, the app is launched, but no addOnMessageReceivedCallback / onMessageReceivedCallback
is triggered.
Can you please share a snippet of what works for you, when the app is invoked from the notification?
ngOnInit() {
// ...
Firebase.init({
onMessageReceivedCallback : (message : Message) => {
console.log('Message:');
console.log('title', message.title);
console.log('body', message.body);
// This callback is called when app started with empty values. Check that.
if(!message.title || !message.body) {
return;
}
if(message.foreground) {
LocalNotifications.schedule([{
title : message.title,
body : message.body
}]);
}
},
onPushTokenReceivedCallback : (token : string) => {
console.log(token);
this.fcmToken = token;
}
}).then(
(instance) => {
console.log('firebase started');
},
(error) => console.dir(error)
);
// ...
}
I need to know which notification user tapped so that I can show related content when app started. I searched for this but couldn't find a solution. Some of the solutions are specifically for Android. Is there a cross platform Nativescript way for this?