我正在尝试从我的应用程序发送推送通知,我已经配置了所有内容。配置完成后我获得了cert.pem和key.pem。我已按照此https://blog.engineyard.com/2013/developing-ios-push-notifications-nodejs链接进行操作。我能够连接苹果服务器,但无法发送通知。可以任何人帮助我可能是什么问题,因为我已经尝试了很多,但没有得到一个适合我的问题的解决方案。我使用以下代码来通信苹果服务器 提前谢谢。
var http = require('http');
var apn = require('apn');
var url = require('url');
var myPhone = "f0e56d999e14ab0504b403efd39b90deb49306045b4ed698e33602abaa862111";
var myDevice = new apn.Device(myPhone);
var note = new apn.Notification();
note.badge = 1;
note.sound = "r.mp3";
note.alert = { "body" : "Your turn!", "action-loc-key" : "Play" , "launch-image" : ""};
note.payload = {'messageFrom': 'Holly'};
note.device = myDevice;
var callback = function(errorNum, notification){
console.log('Error is: %s', errorNum);
console.log("Note " + notification);
}
var options = {
gateway: 'gateway.sandbox.push.apple.com', // this URL is different for Apple's Production Servers and changes when you go to production
errorCallback: callback,
cert: __dirname+'/_certs/cert.pem',
key: __dirname+'/_certs/key.pem',
passphrase: null,
port: 2195,
enhanced: true,
cacheLength: 100
}
var apnsConnection = new apn.Connection(options);
apnsConnection.sendNotification(note);