On Ubuntu Linux I am running node.js 0.12.7 and I have installed npm package "apns". I wish to send push notifications to apple devices and later on to Android and Windows.
I have very basic code but am still running into issues. The script throws following run time error:
pankaj@pankaj-Ubuntu-asus:~/nodeServer/testCode$ node testPushDirectToApple.js
[Wed Sep 09 2015 02:32:12 GMT-0400 (EDT)] Send : 6840038dee0ac6aa3c4a5210746961e80ed9797410a5100f8835b8dfbb
[Wed Sep 09 2015 02:32:12 GMT-0400 (EDT)] open socket
[Wed Sep 09 2015 02:32:12 GMT-0400 (EDT)] drain
/home/pankaj/node_modules/apns/lib/connection.js:193
if(this.tlsConnection && this.tlsConnection.socket.bufferSize !== 0)
^
TypeError: Cannot read property 'bufferSize' of undefined
at Connection.drain (/home/pankaj/node_modules/apns/lib /connection.js:193:54)
at TLSSocket.<anonymous> (/home/pankaj/node_modules/apns/lib/connection.js:171:12)
at TLSSocket.g (events.js:199:16)
at TLSSocket.emit (events.js:104:17)
at TLSSocket.<anonymous> (_tls_wrap.js:950:16)
at TLSSocket.emit (events.js:104:17)
at TLSSocket._finishInit (_tls_wrap.js:460:8)
Here is my code: "testPushDirectToApple.js"
var apns = require("apns"), notification, options, connection;
options = {
keyFile : "privateKey_key.pem",
certFile : "aps_development_cert.pem",
passphrase: "<scrubbed>",
gateway: "gateway.sandbox.push.apple.com",
port: 2195,
debug : true
};
function pushviaDirectConenction(deviceToken, message){
connection = new apns.Connection(options);
notification = new apns.Notification();
notification.alert = message;
notification.device = new apns.Device(deviceToken);
connection.sendNotification(notification);
}
pushviaDirectConenction("68c2440038dee0ac6aa3c4a5210746961e80ed9797410a5100f8835b8d", "Hi there");
Please advice how to resolve this.
Thanks in advance.
I had the same problem and I found out that I was using the wrong library.
The correct one is this: https://github.com/argon/node-apn
Be careful because there is another one library called node-apns which I think is not continued and deprecated.
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