简体   繁体   English

APN反馈服务不发送令牌

[英]APN Feedback service does not send tokens

I implemented a node.js script that queries the APN Feedback service to retrieve the list of invalid tokens. 我实现了一个查询APN反馈服务的node.js脚本,以检索无效令牌的列表。 Unfortunately, I did not manage to get any invalid token. 不幸的是,我没有得到任何无效的令牌。 I followed these steps: 我按照以下步骤操作:

  1. Install the ios app with push notifications in sandbox mode. 沙盒模式下安装带有推送通知的ios应用。
  2. Send some notifications to the app (done successfully). 向应用发送一些通知(成功完成)。
  3. Uninstall the app (I read that if the app that I uninstall is the only one with push notifications, it will cause the disconnection from the APN Service and make impossible to notify it that the app was uninstalled; but this is not my case, the iPad has many push notification apps installed!!). 卸载该应用程序(我读到,如果我卸载的应用程序是唯一带有推送通知的应用程序,它将导致与APN服务的连接断开,并且无法通知它该应用程序已被卸载;但这不是我的情况, iPad已安装许多推送通知应用程序!)。
  4. Send many other notifications with the same token, about ten or twenty, just to prove that the application token is not valid anymore (obviously the notifications are not delivered because the app has just been uninstalled). 使用相同的令牌(大约十或二十)发送许多其他通知,只是为了证明该应用程序令牌不再有效(显然,由于刚刚卸载了该应用程序,因此未传递通知)。
  5. Query the Feedback service to finally get the invalid token. 查询反馈服务以最终获得无效令牌。 The Feedback service does not send anything, it just closes the connection without any kind of data. 反馈服务不发送任何信息,它只是关闭连接而没有任何类型的数据。

This is the script I use to query the feedback service: 这是我用来查询反馈服务的脚本:

function pollAPNFeedback() {
    var certPem = fs.readFileSync('apns-prod-cert.pem', encoding='ascii');
    var keyPem = fs.readFileSync('apns-prod-key-noenc.pem', encoding='ascii');
    var options = { key: keyPem, cert: certPem };

    console.log("Connecting APN feedback service");

    var stream = tls.connect(2196, 'feedback.sandbox.push.apple.com', options, function() {
        if (stream.authorized == false) {
            return console.log('not connected')
        } else {
            console.log('connected');
        };


        var bufferlist = [];
        stream.on('data', function(data) {
            // APN feedback starts sending data immediately on successful connect
            console.log('-->Data: ', data);
            //bufferlist.push(data);
        });

        stream.on('readable', function(){
            console.log('we have incoming data');
        });

        stream.on('error', function(err){
            console.log('error: ', err);
        });

        stream.on('close', function(){
            console.log('closed');
            console.log('stream.data = ', stream.data);
        });
    });
}

As you can see, I put some listeners on the stream variable. 如您所见,我在流变量上添加了一些侦听器。 The callback function on the 'data' listener is never invoked, only the 'close' event triggers its callback. 永远不会调用“数据”侦听器上的回调函数,只有“关闭”事件会触发其回调。 I am sure that the connection is up because stream.authorized is true. 我确定连接已经建立,因为stream.authorized为true。 What am I doing wrong? 我究竟做错了什么?

Is it possible that you are using a production certificate to contact the sandbox environment? 您是否可能使用生产证书来联系沙盒环境?

From your code : 从您的代码:

var certPem = fs.readFileSync('apns- prod -cert.pem', encoding='ascii'); var certPem = fs.readFileSync('apns- prod -cert.pem',encoding ='ascii');

var keyPem = fs.readFileSync('apns- prod -key-noenc.pem', encoding='ascii'); var keyPem = fs.readFileSync('apns- prod -key-noenc.pem',encoding ='ascii');

And : 和:

var stream = tls.connect(2196, 'feedback. sandbox .push.apple.com', options, function() VAR流= tls.connect(2196, '反馈。 沙箱 .push.apple.com',选项()的函数

If that's the case, that's why it doesn't work. 如果是这样,那就是为什么它不起作用的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM