I'm using apn for sending push notification from node.js App to Apple.
My code:
// send to development****
var dev_cert_path = path.join(__dirname, '..', 'cert.pem');
var dev_key_path = path.join(__dirname, '..', 'key.pem');
var devOptions = { "gateway": "gateway.sandbox.push.apple.com" , "cert": dev_cert_path, "key": dev_key_path, "passphrase":'XXXXX'};
var devApnConnection = new apn.Connection(devOptions)
, devMyDevice = new apn.Device(token)
, devNote = new apn.Notification();
devNote.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
devNote.badge = 3;
devNote.sound = "xxx.aiff";
devNote.alert = message;
devNote.payload = {'messageFrom': ''};
devApnConnection.pushNotification(devNote, devMyDevice);
var options = {
"batchFeedback": true,
"interval": 1
};
var devFeedback = new apn.Feedback(options);
devFeedback.on("feedback", function(devices) {
devices.forEach(function(item) {
logger.debug("device error : " + item.device);
// Do something with item.device and item.time;
});
});
devApnConnection.on('transmitted', function(res){
logger.debug("sent this message:"+JSON.stringify(devNote)+ " to this device: " + devMyDevice);
});
devApnConnection.on('error', function(res){
logger.error("sending message failed to this device: " + devMyDevice + " data: " + JSON.stringify(res) );
});
}
catch(e)
{logger.error("Push notification error: ",e.message);}
My problem:
When sending a request to node.js, it sending a push notification, but I'm getting many Enter PEM pass phrase:
in the terminal:
/projects/my_app$ node app.js
POST /requests 200 14ms
Enter PEM pass phrase:
Enter PEM pass phrase:
Enter PEM pass phrase:
Enter PEM pass phrase:
Enter PEM pass phrase:
Enter PEM pass phrase:
So my App is stuck untill restarting the node... Any idea?
Edit:
I tried to remove the password from the file:
openssl rsa -in key.pem -out nopassword.pem
But I'm still getting this in app console - but when pressing enter, it stops shooting this message, until the next request (before removing the pass, it show many messages until restarting the app, also when clicking enter, or the pass phrase)...
I found the problem...
I had to add cert, key and passphrase to the feedback options.
var options = {
"batchFeedback": true,
"interval": 300
};
var devFeedback = new apn.Feedback(options);
devFeedback.on("feedback", function(devices) {
devices.forEach(function(item) {
logger.debug("device error : " + item.device);
// Do something with item.device and item.time;
});
});
The options should be:
var options = {
"batchFeedback": true,
"interval": 1,
"production": false,
"cert": dev_cert_path,
"key": dev_key_path,
"passphrase":'XXXXX'
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With