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.