1

我正在关注这个网站上的教程:

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);
});
4

1 回答 1

0

您需要添加

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

agent.set('pfx file', pfx).enable('sandbox');
于 2015-03-16T10:23:09.303 回答