5

I am using FCM for push notifications on react native android but the issue is I am able to receive notification and it appears on console but not shown on device or emulator.

My code is as below

componentDidMount(){
  PushNotification.configure({

        onRegister: function (token) {
            console.log('TOKEN:', token);
        },

        onNotification: function (notification) {
            console.log('NOTIFICATION:', notification);

            //I AM ABLE TO SEE THE CONSOLE LOG BUT NOTIFICATION DOESN'T APPEAR ON THE DEVICE
        },

        senderID: "",

        permissions: {
            alert: true,
            badge: true,
            sound: true
        },

        popInitialNotification: true,

        requestPermissions: true,
    });
}

1 Answers1

0
Need to create Local Notification then display notification in emulator or android device please use below code inside onNotification method.

  var PushNotification = require('react-native-push-notification');

  onNotification: function (notification: any) {
    const {
      foreground,
      userInteraction,
      message,
      id,
      data,
      ...rest
    } = notification;
    //code for android
      if (foreground && !userInteraction) {
        PushNotification.localNotification({
          ...rest,
          data,
          message,
          autoCancel: true,
        });
        PushNotification.android.setAutoCancel(true);
      }
}
Satyawan Hajare
  • 1,112
  • 11
  • 10