Foreground notifications when app is opened contain empty data

#1

On iOS, foreground notifications when app is opened contain empty data. I receive an event when the notification is received thanks to the following line

this._notificationSubscription = Notifications.addListener(this._handleNotification);

But when I handle the payload, there is no data inside.

_handleNotification = ({ origin, data }) => {
    console.log(
      `Push notification ${origin} with data: ${JSON.stringify(data)}`
    );
  };

However when the app is closed or in the background, the standard iOS notifications provide the data as title and body.



How to access title & body text from a notification event?
#2

The difference here is iOS’s display of notifications vs. what Expo programmatically exposes. (Foreground vs. background is unrelated.) We would like to expose the displayed data in the programmatic data on iOS but currently don’t right now.

For now, you want to access the data programmatically you can send it in the “data” field of the payload, covered in the push notification docs.

#3

Ok thank you for the answer ! I will deal with the data field.

closed #4

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