我已成功设置后端以使用“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);
}
如有任何帮助,我们将不胜感激。谢谢
您的有效负载应如下所示:
const payload = {
notification: {
title: "title",
body: `body`,
},
apns: {
payload: {
aps: {
badge: 1,
},
},
},
token: receiverFcmToken
};
const message = {
notification: {
title: category.title,
body: category.message,
},
apns: {
payload: {
aps: {
badge: 1,
sound: 'default'
},
},
},
token: fcmToken
};
这个有效负载对我有用。