react-native-notifications icon indicating copy to clipboard operation
react-native-notifications copied to clipboard

Reverting back to 1.5 - iOS background notifications and consumeBackgroundQueue

Open calcazar opened this issue 7 years ago • 7 comments

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

calcazar avatar Sep 27 '19 19:09 calcazar

You should consume the initial push notification using getInitialNotification api.

const initialNotification = await NotificationsIOS.getInitialNotification();

yogevbd avatar Oct 02 '19 08:10 yogevbd

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 avatar Oct 02 '19 17:10 ahmadworks

@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 avatar Oct 03 '19 09:10 yogevbd

@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 avatar Oct 08 '19 13:10 calcazar

@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);
      }
    });
  };

tomoima525 avatar Oct 17 '19 17:10 tomoima525

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Nov 16 '19 17:11 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Nov 23 '19 18:11 stale[bot]