【发布时间】:2018-01-29 12:10:58
【问题描述】:
在服务器端,发送苹果推送通知的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);
});
事实上,每次我发送推送并在我的数据库中增加 badge + 1
当在设备上读取推送时,我减一 徽章 - 1
每次发送新推送时,总是发送当前数量的徽章 但是如果设备离线则无法推送,但数据库中的数字已经增加了。
我怎样才能更正计数徽章?
【问题讨论】:
标签: apple-push-notifications apn node-apn