react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

How to display foreground notifications with the current version 6

Open dreson4 opened this issue 6 years ago • 4 comments

I have background notifications showing fine, but I also want to show notifications when I receive them on foreground for some very important tasks.

I have read the documentation, I don't see anywhere with local notifications examples.

Previous versions used to have a method like this one

const notification = new firebase.notifications.Notification()
firebase.notifications().displayNotification(notification);

How do I display notifications within the app with the current version?

dreson4 avatar Apr 24 '20 17:04 dreson4

You need to use a local notifications library. We're building Notifee, however there are free alternatives available too.

FCM is only responsible for displaying remotes.

Ehesp avatar Apr 24 '20 22:04 Ehesp

I use a combination from wix-navigation and this library for display notification. Something like this

	import messaging from '@react-native-firebase/messaging';
	import { Notifications } from 'react-native-notifications';

	messaging().onMessage(async (remoteMessage) => {
      console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
      Notifications.postLocalNotification(
        remoteMessage.notification,
        parseInt(remoteMessage.messageId.match(/\d+/g).join(''), 10),
      );
    });

In the componentMount of my notificationHandler

ccanalesb avatar May 06 '20 16:05 ccanalesb

Is there any update

himanshi7046 avatar Sep 18 '20 11:09 himanshi7046

@himanshi7046 do you see any updates here? If not, there are no updates. This is an issue closed from April 30, why would there be updates? That's not how things work in open source - it's all in the open so what you see is what you get. Opening new issues with full details is the way to get new information vs posting on closed issues

mikehardy avatar Sep 18 '20 13:09 mikehardy