Notifications.addListener not firing

Hi,

I am trying to use Notificaitons.addListener in App.js (on iOS standalone production build), but it does not seem to fire although notifications are successfully received. Here’s the code:

Notifications.addListener(payload => {
  Sentry.captureMessage("RECEIVED NOTIFICAITON",  {
    level: 'info',
    extra: {
      title: JSON.stringify(payload.title),
      body: JSON.stringify(payload.body),
      data: JSON.stringify(payload.data)
    }
  });
});

We are using Firebase notifications, but I don’t think this is relevant since the notifications work fine. Any idea where could be the problem?

Sentry logging works fine in other parts of the app.

Thanks

edit: I have noticed that SDK 26 was supposed to fix some issues with addListener, but there is no change after updating from SDK 25

2 Likes

I am also having the same issue. I am currently still working in development, using Expo XDE. Notifications are working correctly on iOS device when the app is not open and foreground. When the app is open and foreground, the listener passed to Notifications.addListener() never fires, so I am unable to manually handle the notification per https://docs.expo.io/versions/latest/guides/push-notifications#3-handle-receiving-andor-selecting-the-notification.

  handleNotification = (notification) => {
    console.log('notification recieved!', notification);
    this.setState({ notification });
  }

  registerForPushNotificationsAsync = async () => {
    // code to register token

    this.notificationSubscription = Notifications.addListener(this.handleNotification);
  }

Searching the forums a bit, looks like this post is describing the same problem: Expo push notification handler not sending data - #2 by dikaiosune.
Any help would be appreciate.

1 Like

Same things here. I placed Notificaitons.addListener inside componentDidMount function in the main navigator, the listener is not firing up if the app is opened and foreground

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.