Reverting back to 1.5 - iOS background notifications and consumeBackgroundQueue
For the time being, my team is reverting back to 1.5 since the 2.x versions removed background notification support for iOS.
Without consumeBackgroundQueue, when a push notification is sent to iOS and the app is "dead"/closed/swiped away, the first push notification gets ignored. If you send a second push notification then everything works fine.
With consumeBackgroundQueue, we call that on app launch and then all push notifications get processed as expected including the inital push.
Our app works as follows:
We send a silent notification to the app The (closed) app receives the silent notification The app reaches out to our service to say the user received a notification The app creates a noisy local notification to show the user the notification
The above use case works well in 1.5 but is broken in 2.x
You should consume the initial push notification using getInitialNotification api.
const initialNotification = await NotificationsIOS.getInitialNotification();
Does the current version contain consumeBackgroundQueue? if not when will you release it? I am depending on your module and I am currently not receiving any notifications on background.
@ahmadworks consumeBackgroundQueue didn't return any other notification except the initial notification and therefor it was a useless api.
This is how you should consume the initial notification:
const initialNotification = await NotificationsIOS.getInitialNotification();
@yogevbd getInitialNotification only gets called when I tap on the notification received. without consumeBackgroundQueue(), the first push notification that an iOS device receives does not execute.
This can also be reproduced in the sample project. I think consumeBackgroundQueue() existed to manually trigger what getInitialNotification references
@calcazar I was able to get the notification payload when the app is closed by the code below(2.1.3)
componentDidMount() {
NotificationsIOS.addEventListener('notificationReceivedForeground', this.handleNotification);
// When app is in background
NotificationsIOS.addEventListener('notificationOpened', this.handleNotification);
// When app is closed
this.checkIfLaunchedByPushNotification();
}
componentWillUnmount() {
NotificationsIOS.removeEventListener('notificationReceivedForeground', this.handleNotification);
NotificationsIOS.removeEventListener('notificationOpened', this.handleNotification);
}
checkIfLaunchedByPushNotification = () => {
NotificationsIOS.getInitialNotification().then(notification => {
if (notification) {
this.handleNotification(notification);
}
});
};
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
The issue has been closed for inactivity.