首页 > 解决方案 > 收到通知时如何在 react native/Node.js 中设置徽章?

问题描述

当用户收到通知时,我无法找出如何设置徽章(应用左上方的红色圆圈)。逻辑假设在前端还是后端?我使用 React Native 作为前端,使用 Node.js 作为后端,并使用 firebase 进行推送通知。

目前,通知有效,但未显示红色徽章。

收到通知时我的后端(Node.js)

const admin = require('firebase-admin');

const payload = {
  notification: {
    title: `Test`,
    body: `Hi`,
    // badge: 1 Throws error : Invalid JSON payload received. Unknown name
  },
  token: 'someFCMToken',
};

try {
  await admin
    .messaging()
    .send(payload)
    .then((response) => {
      console.log(response + ' notification were sent successfully');
    });
} catch (err) {
  console.log(err);
}

标签: node.jsfirebasereact-nativefirebase-notifications

解决方案


推荐阅读