推送通知 - 如何设置特定用户的徽章计数?

问题描述

用户向另一个用户发送聊天消息时,我想更新接收者徽章计数。 expo-notifications 是否有任何功能可以让您通过特定用户的令牌查看其徽章计数?像这样:

const PushNotifications = async (receiverId,messageBody,user = null) => {
  let token = tokenMap[receiverId];
  let count = await Notifications.getBadgeCountAsync(token);

  if (!token) {
    // pick latest token of user
    token = await getLatestToken(receiverId);
    tokenMap[receiverId] = token;
  }

  const message = {
    to: token,sound: "default",title: messageBody.title,body: messageBody.body,badge: count + 1,data: {
      message: messageBody,sender: {
        id: user.id,name: user.infoData.fullName,},_displayInForeground: true,};

  try {
    if (!token) {
      return;
    }
    const response = await fetch("https://exp.host/--/api/v2/push/send",{
      method: "POST",headers: {
        Accept: "application/json","Accept-encoding": "gzip,deflate","Content-Type": "application/json",body: JSON.stringify(message),});
  } catch (exp) {
    console.log(`error sending notification ${exp.message}`);
  }
};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...