0
votes

I'm trying to get notifications and update launcher icon badge on IOS with React-Native/RNFirebase when app is closed. But unfortunately it seems RNFirebase doesn't have any support for it. onNotification() listener doesn't seem working when app is closed. (background modes/push notifications are enabled on XCode)

Is there any workaround for that to update launcher icon badge when notification received and app is closed?

1

1 Answers

0
votes

If your app is closed, you can check if it was opened by a notification using: firebase.notifications().getInitialNotification()

here is a sample using it:

const notificationOpen = await firebase
      .notifications()
      .getInitialNotification();
    if (notificationOpen && notificationOpen.notification) {
      let { title, body, data } = notificationOpen.notification;
      if (!title && !body) {
        title = data.title;
        body = data.body;
      }

      const notification: Notification = notificationOpen.notification;
      //firebase.notifications().removeDeliveredNotification(notification.notificationId);
      this.handleNotificationActions(
        title,
        body,
        data,
        navigator,
        t,
        "background"
      );
    }