var apn = require(‘apn’);
var token = 'a788a70f…79ecc6145’; //长度为64的设备Token
var options = { "gateway": “gateway.sandbox.push.apple.com” }, apnConnection = new apn.Connection(options), device = new apn.Device(token), note = new apn.Notification();
note.expiry = Math.floor(Date.now() / 1000) + 60; note.badge = 3; note.alert = "动漫驿站 \n点击查看更新的1篇文章"; note.payload = {’messageFrom’: 'Caroline’};
apnConnection.pushNotification(note, device);
apnConnection.on('disconnected’,function() { console.log(“Disconnected from APNS”); }); apnConnection.on('socketError’, console.error);
上面的代码在win8, win7的环境都正常运行. 但是在服务器上面(我用的是win2003系统)和本地xp系统都无法正常运行,返回一下信息: Disconnected from APNS{ [Error: connect UNKNOWN] code: 'UNKNOWN’, errno: 'UNKNOWN’, syscall: ‘connect’ } 其中我本地测试时,xp和win8、win7都是同一网络的,所以我觉得应该可以排除网络问题
这个问题已经困扰我很久了,刚接触nodejs不久,希望大家帮忙看看有什么解决办法。谢谢!!!