推送通知丢失消息

时间:2014-10-14 16:50:44

标签: ios node.js apple-push-notifications engineyard

我正在关注本网站的教程:

https://blog.engineyard.com/2013/developing-ios-push-notifications-nodejs

在我的应用中发送推送通知。

到目前为止,我已成功创建了证书和其他文件。在服务器端,我无法通过“建立连接”步骤。

我可以在运行应用程序时在控制台中获取设备令牌。在教程中,据说,在建立连接之后,终端控制台应该输出"网关连接"。

但我没有得到这个消息。最糟糕的情况是我也没有收到任何错误消息。我想知道出了什么问题。即使我在连接中首先出现了一些错误,例如凭证不足,mac验证错误,我解决了这些错误。现在既没有收到任何错误也没有收到正确的信息。

我也在这里添加我的终端控制台

SIVAs-MacBook-Air:~ AAA$ cd Desktop/
SIVAs-MacBook-Air:Desktop AAA$ cd poservices/
SIVAs-MacBook-Air:poservices AAA$ node agent/_header.js
SIVAs-MacBook-Air:poservices AAA$ node agent/_header.js
SIVAs-MacBook-Air:poservices AAA$`


var join = require('path').join
  , pfx = join(__dirname, '../_certs/pfx.p12');

/*!
 * Create a new gateway agent
 */

var apnagent = require('apnagent')
  , agent = module.exports = new apnagent.Agent();


/*!
 * Configure agent
 */

agent
  .set('pfx file', pfx)
  .enable('sandbox');

/*!
 * Error Mitigation
 */

agent.on('message:error', function (err, msg) {
   connect.log('error1');
  switch (err.name) {

// This error occurs when Apple reports an issue parsing the message.
case 'GatewayNotificationError':
  console.log('[message:error] GatewayNotificationError: %s', err.message);


  // The err.code is the number that Apple reports.
  // Example: 8 means the token supplied is invalid or not subscribed
  // to notifications for your application.
  if (err.code === 8) {        
    console.log('    > %s', msg.device().toString());
    // In production you should flag this token as invalid and not
    // send any futher messages to it until you confirm validity
  }

  break;

// This happens when apnagent has a problem encoding the message for transfer
case 'SerializationError':
  console.log('[message:error] SerializationError: %s', err.message);

  break;

// unlikely, but could occur if trying to send over a dead socket
default:
  console.log('[message:error] other error: %s', err.message);      
  break;
  }
});

/*!
 * Make the connection
 */


agent.connect(function (err) {
  // gracefully handle auth problems
  if (err && err.name === 'GatewayAuthorizationError') {

console.log('Authentication Error: %s', err.message);
process.exit(1);
  }

  // handle any other err (not likely)
  else if (err) {
    console.log('error1');
    throw err;
  }

  // it worked!
  var env = agent.enabled('sandbox')
    ? 'sandbox'
    : 'production';
  console.log('apnagent [%s] gateway connected', env);
});

1 个答案:

答案 0 :(得分:0)

您需要添加

agent.set('passphrase', '<YOUR_PASSWORD>');

agent.set('pfx file', pfx).enable('sandbox');