2

我是 node-apn 的新手。我已经在 nodejs 应用程序中实现了它。下面是我的代码。

var APN = require('apn')
var apnProvider = new APN.Provider({
    token: {
        key: "PATH_TO_FILE",
        keyId: "KEY",
        teamId: "TEAM"
    },
    production: false
});

module.exports = {
    send: function (tokens, message, callBackFn) {

        var note = new APN.Notification({
            alert: "Breaking News: I just sent my first Push Notification",
        });

        // The topic is usually the bundle identifier of your application.
        note.topic = "BUNDLE";

        console.log(`Sending: ${note.compile()} to ${tokens}`);
        service.send(note, tokens).then(callBackFn);
    }
};

所以在一些文档中它说我们应该关闭 apnProvider。

所以我的问题是我应该在全球范围内创建 apnProvider(就像我所做的那样)?

或者我应该创建每个发送请求(内部发送功能)并在发送通知后调用关机。

我尝试在线阅读。但我找不到任何像我的要求这样的例子。

4

0 回答 0