【问题标题】:How to set badge on push notification received in android and ios?如何在 android 和 ios 收到的推送通知上设置徽章?
【发布时间】:2019-09-20 13:46:44
【问题描述】:

当在移动设备上收到推送通知时,我正在尝试使用 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 react-native push-notification firebase-cloud-messaging react-native-firebase


    【解决方案1】:

    如果有人仍然想知道我是如何做到的

     firebase.notifications().setBadge(badgeCount);
    

    【讨论】:

    • 我把这条线放在哪里?
    • @OliverD 您要在其中更新徽章计数,请注意这是 rnFirebase 的 v5
    • 我想在应用程序图标中进行操作,并且在标题组件的应用程序内部,我有一个通知图标“?”
    • 以上行将仅处理应用程序图标,它支持所有 ios 设备和一些 android 设备,因为那里有限制,同时您需要通过 state/redux 等设置通知徽章
    • 谢谢我解决了应用程序内的通知徽章,但默认情况下,徽章图标在 Android 8 中不会出现在我身上,所以我使用 react native firebase v6,我没有看到任何与通知相关的模块所以我不能使用你的代码行:(而且我不知道我该如何处理它
    猜你喜欢
    • 2015-06-14
    • 2016-11-23
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 2019-03-31
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    相关资源
    最近更新 更多