6

I am using expo react native on a project and I am using the expo-notifications package within the project.

I have added "useNextNotificationsApi": true, to my app.json file under the android object which is under the expo object so expo.android.useNextNotificationsApi : true.

I also have the experienceId set on the message I am sending to expo's server from my server, I am using the https://github.com/expo/expo-server-sdk-node package to do the sending.

   messages.push({
               to: red_user.fcm_token,
               sound: 'default',
               title: "Stylist Response",
               body: "Stylist has agreed to fulfill the request",
               data: {
                   experienceId: "@glamcentralng/GlamCentral",
                   order: order._id,
                   stylist_response: "agreed" 
               },
          })  

In my expo react native app I am using the expo-notifications package as I mentioned and I have the following setup in my class component.

import * as Notifications from 'expo-notifications';

.
.
.
.

 componentDidMount() {

    //Not working at all 
    Notifications.addNotificationReceivedListener( notification => {
      console.log(notification);
      this._handleNotification(notification)
    });

    //Working well
    Notifications.addNotificationResponseReceivedListener(response => {
      console.log(response);
    });
  
    this.registerForPushNotificationsAsyncNew();
}

The addNotificationReceivedListener does not receive the notification when it comes in, but I see it as a normal notification on my real Android device (I am NOT using an emulator). AS per the documentation when i click on the notification the addNotificationResponseReceivedListener should handle it and it does. So addNotificationReceivedListener does NOT work but addNotificationResponseReceivedListener works well.

One more thing to add is that I am getting a token in the function that does the registration as per the documentation.

Not sure how to fix this as I have checked other threads on here and github. Any help is appreciated.

Joshua Majebi
  • 1,110
  • 4
  • 16
  • 34
  • Did you find the solution to this? – Afif May 21 '21 at 07:19
  • 1
    addNotificationReceivedListener will get fired whenever a notification is received while the app is foregrounded. https://www.npmjs.com/package/expo-notifications#addnotificationreceivedlistenerlistener-event-notification--void-void – hafij Jul 07 '21 at 11:52

0 Answers0