#StackBounty: #ios #node.js #azure #azure-notificationhub Sending APNS push with Azure and Node.js to iOS not working

Bounty: 50

I need to send push notifications to iOS devices with Azure. I added the Notification Hub and the p12 certificate to it.

This is my node.js code:

async function sendPush(token) {
   var notificationHubService = azure.createNotificationHubService('hub name','connection string');

   // registration is done only once: 
   notificationHubService.apns.createNativeRegistration(token, ['tag_associated_with_token'], null, callback);

   var payload = {
       alert: 'Hello!'
   };

   // send notification to all registered devices: 
   notificationHubService.apns.send(null, payload, null, function(error, response){
     if(!error){
        console.log('notification sent:');
        console.log(response);
     }
     else {
        console.log('error ');
        console.log(error);
     }
  });
}

Everything seems to work. I get a successful registration, and when listing my registrations I can see that it’s there. Sending the notification has a success response:

{ isSuccessful: true,
   statusCode: 201,
   body: '',
   headers:
    { 'transfer-encoding': 'chunked',
      'content-type': 'application/xml; charset=utf-8',
      server: 'Microsoft-HTTPAPI/2.0',
      date: 'Wed, 17 Jul 2019 12:43:40 GMT',
      connection: 'close' },
    md5: undefined 
}  

And that’s it. Looks like all is well. But the device does not get a notification.

The device token is correct. The app allows notifications. When setting the certificate in the Azure portal I tried both production or ‘sandbox’. As far as I can see everything should work. I also tried the Test feature on the portal itself and it reports success but the device doesn’t get anything.

What am I missing?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.