1

I am trying to deliver push notification in my ios app and i user node.js. So I am followint the tutorial from the link: https://blog.engineyard.com/2013/developing-ios-push-notifications-nodejs.

In this tutorial they are keeping the passphrase for the private key as empty. But I am setting a password for my private key and I dont know how to include my password in the coding. I know there has been many angles of answer to this. But am not getting anything works. I tried :

.set('cert file', join(__dirname, '../_cert/apn-dev-cert.pem'))
.set('key file', join(__dirname, '../_cert/apn-dev-key.pem'))
//or this works too:
// .set('pfx file', join(__dirname, '../_cert/Certificates.p12'))
// .set('passphrase', 'your passphrase')
.enable('sandbox')



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

I also tried concatenating the certificate and the key and use it as a single file, nothing works.

János
  • 32,867
  • 38
  • 193
  • 353
AAA
  • 1,957
  • 4
  • 23
  • 42
  • What kind of error messages are you getting, other than Insufficient credentials? Is there another suppressed error? – nityan Oct 18 '14 at 23:38
  • no, i get some errors like mac verify error, auth failed. but i corrected those mistakes. now this is the only error that has to be solved – AAA Oct 19 '14 at 18:55
  • Could you provide a larger code example? – nityan Oct 19 '14 at 21:45
  • In the edited code, I shoud get the last console message, "gateway connected", but am not getting it – AAA Oct 19 '14 at 22:52
  • My experience with APNS is that you have to use .pfx file extensions for the Push certificates. I see you've tried .p12, and I know that on Windows .pfx and .p12 are the same, but have you tried converting your certificate to .pfx? – nityan Oct 19 '14 at 22:57
  • I just tried and am getting the same error. I think i need to add the password for my private key in the code, but i dont know how. maybe thats why I am getting the error as "insufficient credentials" – AAA Oct 19 '14 at 23:26

0 Answers0