如何在安卓和iOS中收到的推送通知上设置徽章?



当在移动设备上收到推送通知时,我正在尝试使用反应原生火力在应用图标上设置徽章计数。但无法动态设置应用程序图标上的计数值。

这是我的代码 -

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

最新更新