如何在 ios 中设置徽章计数 Firebase 推送通知?

问题描述 投票:0回答:2

我已成功设置后端以使用“firebase-admin”发送通知。但是,我在为我的 ios 设置徽章计数时遇到问题。我目前正在使用 React Native 和 Node.js TypeScript 作为后端。

发送时我的后端管理如下所示:

const payload = {
            notification: {
                title: "title",
                body: `body`,
              //badge: 1 this throws an error
            },
            token: receiverFcmToken
        };

        try{
            await admin.messaging().send(payload).then((response) => {
                console.log("success);
            });
        } catch(err){
            console.log(err);
        }

如有任何帮助,我们将不胜感激。谢谢

node.js firebase react-native firebase-cloud-messaging firebase-notifications
2个回答
2
投票

您的有效负载应如下所示:

const payload = {
    notification: {
        title: "title",
        body: `body`,
    },
    apns: {
      payload: {
        aps: {
          badge: 1,
        },
      },
    },
    token: receiverFcmToken
};

0
投票
const message = {
    notification: {
        title: category.title,
        body: category.message,
    },
    apns: {
        payload: {
            aps: {
                badge: 1,
                sound: 'default'
            },
        },
    },
    token: fcmToken
};

这个有效负载对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.