gpt4 book ai didi

node.js - 我正在尝试将 Apns 库用于 node.js,但出现错误 - "TypeError: Cannot read property ' bufferSize' of undefined”

转载 作者:搜寻专家 更新时间:2023-10-31 23:42:02 25 4
gpt4 key购买 nike

在 Ubuntu Linux 上,我正在运行 node.js 0.12.7 并且我已经安装了 npm 包“apns”。我希望将推送通知发送到 Apple 设备,然后再发送到 Android 和 Windows。

我有非常基本的代码,但仍然遇到问题。该脚本抛出以下运行时错误:

  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)

这是我的代码:“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");

请指教如何解决这个问题。

提前致谢。

最佳答案

我遇到了同样的问题,我发现我使用了错误的库。

正确的是:https://github.com/argon/node-apn

要小心,因为还有另一个名为 node-apns 的库,我认为它不会继续使用并且已弃用。

关于node.js - 我正在尝试将 Apns 库用于 node.js,但出现错误 - "TypeError: Cannot read property ' bufferSize' of undefined”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32472859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com