Issue
I am trying to receive notifications using Firebase in Angular. I do get the notification when it gets triggered. However, the title and the body that should be in the notification do not do so. I have tried various solutions but am unable to do it. At one place, I read at one of the blogs while searching for the solution that it gets the point that it has to push notification, however, it's not able to receive the title and body properly.
Also, it's working fine on React App from Laravel Side, but not in Angular.
The notification I get I am attaching it below. Please guide me.
const app = initializeApp(firebaseConfig); //firebaseConfig is my firebase configurations
const messaging = getMessaging();
getToken(messaging, { vapidKey: 'BPupbI-8TFUeiPhfTI43JW5BZ7uDd3vAqba1w1YHR3H8mqIswifdGByxr0Vbz0ENqjJyFjOi0ptyqM5w3wBH3bc' })
.then((currentToken) => {
if (currentToken) {
localStorage.setItem('fcm_token', currentToken)
this.fcm_token = currentToken
console.log('guest', this.fcm_token)
// Track the token -> client mapping, by sending to backend server
// show on the UI that permission is secured
} else {
console.log('No registration token available. Request permission to generate one.');
// shows on the UI that permission is required
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
// catch error while creating client token
});
onMessage(messaging, (payload) => {
alert(1);
console.log('asdasdasdasdg1')
console.log('Message received. ', payload, payload.data.body);
// return
// ...
});
Also, anywhere this code is, the notification gets triggered whether the onMessage function exists or not. And, I don't think that onMessage gets triggered anyways since the console.log and alert doesn't execute.
Solution
Try using old version of Firebase, I was having the same issue with Firebase 9 even though I was using the official documentation.
On Using 8.10 version, it worked like a charm.
Answered By - Maisum Abbas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.