wix / react-native-notifications

React Native Notifications
MIT License
3.23k stars 763 forks source link

Can't receive any notification in android #879

Closed javitolin closed 2 years ago

javitolin commented 2 years ago

Hi, I'm able to receive the device token, but when I try sending a notification from my Node.js server it doesn't work.

This is how I send a notification:

const message = {
  data: {
    score: '850',
    time: '2:45'
  },
  token: "DEVICE-TOKEN"
};

admin
  .messaging()
  .send(message)
  .then((response) => {
    console.log("Notification sent successfully", response);
  })
  .catch((error) => {
    console.log(error);
  });

and I receive success with the notification ID.

In the react-native app I've followed the manual and seen the example but I can't get it to receive the notification. I call Notifications.registerRemoteNotification(); and receive the token successfully. This is how I subscribe to events:

 Notifications.events().registerRemoteNotificationsRegistered((event) => {
      // TODO: Send the token to my server so it could send back push notifications...
      console.log("Device Token Received", event.deviceToken);
    });
    Notifications.events().registerRemoteNotificationsRegistrationFailed(
      (event) => {
        console.error(event);
      }
    );

    Notifications.events().registerNotificationReceivedBackground(
      (notification, completion) => {
        console.log(
          `Notification received in background: ${notification.title} : ${notification.body}`
        );
        completion({ alert: true, sound: true, badge: true });
      }
    );

    Notifications.events().registerNotificationReceivedForeground(
      (notification, completion) => {
        console.log(
          `Notification received in foreground: ${notification.title} : ${notification.body}`
        );
        completion({ alert: true, sound: true, badge: true });
      }
    );

    Notifications.events().registerNotificationOpened(
      (notification, completion) => {
        console.log(`Notification opened: ${notification.payload}`);
        completion();
      }
    );

(Just like the example)

Notifications.postLocalNotification isn't working either

Any thoughts? Thanks

javitolin commented 2 years ago

My bad, I haven't completely uninstalled react-native-push-notifications and that was colliding with this library. After removing everything from the other library it works fine. Thanks