Upgrading Notifications SDK34 to SDK41

I’m upgrading my app to SDK41 and it’s gone pretty smoothly except I’m having trouble getting at the data payload when handling received notifications

I used to do this…

  componentDidMount() {
    this.notificationSubscription = Notifications.addListener(notification =>
      this.handlePushNotification(notification),
    );
  }

and the notification.data had an eventid property that I could extract.

In the newer expo-navigation I’ve changed this to…

Notifications.addNotificationReceivedListener(notification =>
  this.handlePushNotification(notification),
);

and my function gets called when my app is foregrounded and I can see the notification data if I console.log:

console.log(‘notification data:’, notification.request.trigger.remoteMessage.data.body);

notification data: {“eventid”:3157,“dataasat”:“2021-08-05 18:13”…

But I must be missing something fundamental because I can’t seem to access the eventid. I do:

console.log(‘notification eventid:’, notification.request.trigger.remoteMessage.data.body.eventid);

and get:
notification eventid: undefined

It’s driving me mad so I’d be hugely grateful if someone could help me get at the notification data.

TIA

Dan

I think I must have been having a brain fart - data is in notification.request.content.data as documented!

So a notification received while the app is foregrounded now works fine :slight_smile:

I’m now attempting to use Notifications.addNotificationResponseReceivedListener() in order to also handle the scenario where a user clicks a notification when the (Android) app is not running.

    Notifications.addNotificationResponseReceivedListener(notification =>
      this.handlePushNotification(notification),
    );

What happens is that the app is launched but the listener is not called. Is this likely to be down to the scenario described in Receiving Notifications - Expo Documentation and is there anything I can do to minimise the effect? I’m using Notifications.setNotificationChannelAsync() to set importance to Notifications.AndroidImportance.MAX in my App.js and testing with battery saver off.

TIA

Dan

In particular do the limitations referred to in Receiving Notifications - Expo Documentation refer to the delivery of the notification to the phone or to the app when a notification is clicked on? I’m getting the notification delivered to the phone but though clicking on it will open the app when closed it doesn’t go through my NotificationResponseReceivedListener().

TIA

Dan

OK, I assume this is either impossible or at least difficult so I’ve re-implemented my app so that it gets notification data directly from the backend in addition to the push notification messages. This seems to be the only way I can cope with notifications arriving whilst the app is not running.

Dan

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