Can't get badge count when app is not in foreground - react native iOS

不打扰是莪最后的温柔 提交于 2020-12-16 03:50:29

问题


I can't get the badge count on ios when the app is in the background and closed. I have referred this issue #1824. But it has closed, I didn't get any solution from that.

I am sharing a piece of code what I have used to get notifications

this.notificationListener = firebase
      .notifications()
      .onNotification(async (notification) => {

        const localNotification = new firebase.notifications.Notification({ show_in_foreground: false })
          .setNotificationId(notification.notificationId)
          .setTitle(notification.title)
          .setBody(notification.body)
          .setData(notification.data)
          .android.setChannelId("fcm_default_channel")
          .android.setSmallIcon("@drawable/wasfat")
          .android.setAutoCancel(true)
          .android.setColor("#b61b33")
          .android.setPriority(firebase.notifications.Android.Priority.High);

        let badgeCount = await firebase.notifications().getBadge();
        firebase.notifications().setBadge(badgeCount + 1);

        firebase.notifications().displayNotification(localNotification).catch(err => { });
      });

from the above code, I'm getting notification very fine in all cases. But I'm able to get badge count, only app is in the foreground.

Please suggest, If anything I have missed to get badge count when the app is in the background and closed.

I am facing this only on ios. For android, it is working fine without the setBadge() method.

Platform: iOS 

react-native: 0.61.5

react-native-firebase: 5.5.6

Thanks for any help.

来源:https://stackoverflow.com/questions/62528961/cant-get-badge-count-when-app-is-not-in-foreground-react-native-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!