I've had several issues migrating from react native firebase v5 to v6. It seems that there's no notifications() method in v6. How to properly display the notifications in foreground with react native firebase v6?
my code with v5 works:
async listenToPushNots(){
firebase.notifications().onNotificationDisplayed(notification => {
console.log("XXXXX onNotificationDisplayed", notification);
});
firebase.notifications().onNotification(notification => {
//remote notification received
console.log("XXXXX LISTENER onNotification", notification);
// notification.android.setChannelId(notification._notificationId);
// firebase.notifications().displayNotification(notification);
const localNotification = new firebase.notifications.Notification({
sound: "default",
show_in_foreground: true,
show_in_background: true
})
.setNotificationId(notification._notificationId)
.setTitle(notification._data.title)
.setSubtitle(notification._data.body)
.setBody(notification._data.body)
.setData(notification._data)
.android.setChannelId("my-app-channel")
.android.setSmallIcon("ic_stat_ic_notif") // create this icon in Android Studio
.android.setLargeIcon("ic_launcher_round")
.android.setColor("#000000") // you can set a color here
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase
.notifications()
.displayNotification(localNotification)
.catch(err => console.error(err));
}
async componentDidMount(){
listenToPushNots();
}
In v6 how would firebase.notifications() be replaced? There is no reference in their official docs on how to properly migrate (https://rnfirebase.io/messaging/notifications). The messaging() method does not include notifications unlike v5.
As you can see from their documentation (https://rnfirebase.io/messaging/usage), you can't use react-native-firebase v6 for foreground notification:
The best way to add foreground notification, is to add https://github.com/zo0r/react-native-push-notification