Foreground notifications when app is opened contain empty data

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.



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.

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

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