3

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?

Eddy
  • 3,533
  • 13
  • 59
  • 89

4 Answers4

0

If you are using your phone on a wifi network since you are in development. If this is the case, you may want to check that your router is not blocking the unusual ports apple uses for the apns sandbox. If this is your case you may want to try forwarding the ports: 2195 5223. You may also try turning off wifi all together and trying your cellular network instead.

Hope it helps.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
  • It did not help. No push was received. Moreover all the registrations from yesterday disappeared, and when I'm creating a new one today it only stays for a few seconds and then disappears. – Eddy Jul 18 '19 at 15:04
0

Things to check

  1. Check if that device udid is added in provisioning profile(not needed for distribution builds)
  2. Check the payload if it has all the keys required
Mohan Meruva
  • 322
  • 1
  • 3
  • 11
  • The device is getting notifications using other libraries, so I doubt these are the reasons. – Eddy Jul 25 '19 at 13:28
0

You need the "alert" key inside an "aps" object.

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

Apple's reference page for remote notifications has more detail, of course.

Eric Hedstrom
  • 1,627
  • 10
  • 13
0

As far as I know iOS app need body and title in their push notifications.

Anyway, do you test it on debug mode in your iOS app with xcode? or only manual testing?

And do you test these with same notifications format?

The device is getting notifications using other libraries

Please check these JSON format

{
   “aps” : {
      “alert” : {
         “title” : “Game Request”,
         “subtitle” : “Five Card Draw”
         “body” : “Bob wants to play poker”,
      },
      “category” : “GAME_INVITATION”
   },
   “gameID” : “12345678”
}
antonio yaphiar
  • 450
  • 3
  • 9