通过Node.js发送APNS

时间:2014-11-24 23:39:44

标签: node.js apple-push-notifications

我按照argon/node-apn上的说明发送消息。它似乎工作正常,除非我将connectionTimeout设置为1000,否则进程不会返回。

我的问题:我是否应该设置“connectionTimeout”以便进程返回并继续使用代码,或者我应该做其他事情?

这是我的代码:

var apn = require ('apn/index.js');

var options = {
        cert: './cert.pem',
        key: './key.pem',
        connectionTimeout: 1000,
        production: false
};
var apnConnection = new apn.Connection(options);

apnConnection.on('disconnected', function() {
    console.log("Disconnected from APNS");
});

var token       = '<my token>';

var myDevice    = new apn.Device(token);

var note = new apn.Notification();

note.expiry             = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge              = 777;
note.retryLimit         = 1;
note.sound              = "ping.aiff";
note.alert = "\u2709 Sorry ..... ";
note.payload            = {'messageFrom': 'My Payload'};

apnConnection.pushNotification(note, myDevice);

0 个答案:

没有答案