Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何设置在android和ios中收到的推送通知上的标记?_Firebase_React Native_Push Notification_Firebase Cloud Messaging_React Native Firebase - Fatal编程技术网

Firebase 如何设置在android和ios中收到的推送通知上的标记?

Firebase 如何设置在android和ios中收到的推送通知上的标记?,firebase,react-native,push-notification,firebase-cloud-messaging,react-native-firebase,Firebase,React Native,Push Notification,Firebase Cloud Messaging,React Native Firebase,当在手机上收到推送通知时,我尝试使用react native firebase在应用程序图标上设置徽章计数。但无法动态设置应用程序图标上的计数值 这是我的密码- const channel = new firebase.notifications.Android.Channel( 'demo', 'DEMO', firebase.notifications.Android.Importance.Max ).setDescription('DEMO APP'); firebase.no

当在手机上收到推送通知时,我尝试使用react native firebase在应用程序图标上设置徽章计数。但无法动态设置应用程序图标上的计数值

这是我的密码-

const channel = new firebase.notifications.Android.Channel(
  'demo',
  'DEMO',
  firebase.notifications.Android.Importance.Max
).setDescription('DEMO APP');
firebase.notifications().android.createChannel(channel);

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

    const { title, body, id } = notification.data;
    this.title = title;
    this.body = body;
    this.id = id;

    const localNotification = new firebase.notifications.Notification({
      sound: 'default',
      show_in_foreground: true,
    })
    .setNotificationId(notification.notificationId)
    .setTitle(notification.title)
    .setBody(notification.body)
    .setData(notification.data)
    .setBadge(notification.id)
    .android.setAutoCancel(true)
    .android.setChannelId('demo') // e.g. the id you chose above
    .android.setSmallIcon('ic_launcher') // create this icon in Android Studio
    .android.setColor('#000000') // you can set a color here
    .android.setPriority(firebase.notifications.Android.Priority.High);

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

请帮助任何人找到解决方案。

如果还有人想知道我是如何做到这一点的

 firebase.notifications().setBadge(badgeCount);

我把这行放在哪里?@OliverD你想更新徽章数量,请注意这是RNFireBase的v5我想在应用程序图标中完成,在应用程序标题组件中,我有一个通知图标“上面这一行只处理应用程序图标,它的支持是所有ios设备和一些android设备,因为其中有关于需要通过state/redux等设置的通知徽章的限制Hank you i solve notification badge in the app,但是默认情况下,我在Android 8中不会显示徽章图标,因此我使用react native firebase v6,并且我看不到任何与通知相关的模块,因此我无法使用您的代码行:(我不知道如何处理它。)