Expo push notification handler not sending data

I’m following the docs here: https://docs.expo.io/versions/latest/guides/push-notifications.html

Everything is working except for when the iOS app is open in the foreground.

I handle the push notification listener like this:

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

And here is the _handleNotification function

_handleNotification = (notification) => {
    console.log(notification, 'notification details')

I send a push notification like this through curl:

curl -H "Content-Type: application/json" -X POST https://exp.host/--/api/v2/push/send -d '{   "to": "ExponentPushToken[xxxxxx]",   "title":"hello",   "body": "world" }'

And get a success response, in the Expo XDE console, this is the data that comes through:

Object {
  "data": Object {},
  "origin": "received",
  "remote": true,

As you can see, the data object is empty. Any ideas why?

Things to note:

  • I am using a physical iOS device that does get the push notification properly if the device is not foregrounded.
  • I do need to handle notifications for iOS if the app is foregrounded.

Hi! Could you provide a small example project (maybe on Snack that I can try this curl command with?

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