在服务器端,发送苹果推送通知的nodejs平台使用的是node-apn
这是一个带有徽章的示例 - 这是推送的次数。
const apn = require("apn");
let tokens = ["<insert token here>", "<insert token here>"];
let service = new apn.Provider({
cert: "certificates/cert.pem",
key: "certificates/key.pem",
});
let note = new apn.Notification({
alert: "Breaking News: I just sent my first Push Notification",
badge: countSendedPushes()
});
note.topic = "<bundle identifier>";
service.send(note, tokens).then( result => {
console.log("sent:", result.sent.length);
console.log("failed:", result.failed.length);
console.log(result.failed);
});
事实上,每次我发送推送时,我的数据库徽章都会增加+ 1
当在设备上读取推送时,我减一徽章- 1
每次发送新推送时,我总是发送当前数量的徽章但是如果设备离线它无法推送,但数据库中的数量已经增加。
我怎样才能更正计数徽章?