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

问题描述

用户向另一个用户发送聊天消息时,我想更新接收者徽章计数。 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 (将#修改为@)