Diagnostics of discarded notifications from Azure Notification Hub to APNS

We have (mostly) successfully implemented push notifications for iOS and Android devices through Azure notification hubs.

The problem is that some iOS devices apparently never receive notifications sent by Azure Notification Hubs.

We use templates and tags to direct messages to relevant devices. Tags are topics of interest and never depend on the user, therefore, we expect that one notification for a tag will be transferred to all devices subscribed to this tag.

Android devices seem to receive their notifications flawlessly, but iOS devices are incompatible. Most of them work. The couple does not.

We know well that push notifications are delivered with maximum effort and do not have a guarantee of reliability, but in our limited testing we found more devices that do not receive push notifications in succession than seems unreasonable (more than two failures from about a dozen devices).

Here's the setting:

We have a simple C # procedure on the back that connects to Azure notification hubs and sends out Azure notifications:

var outcome = await hub.SendTemplateNotificationAsync(properties, tag); 

We used the GetAllRegistrationsAsync method to ensure that all the devices we tested successfully registered and used the correct template. Each device is registered, all templates are correct.

We are not in "test mode"; the enableTestSend parameter of the NotificationHubClient.CreateClientFromConnectionString parameter is set to False.

Troubleshooting:

When we send a notification, most devices receive a notification, and in the specific case that we are testing, update the icon counter with the correct number.

However, several devices do not seem to receive a notification. One of the devices received a notification after rebooting the device, but after that it stopped.

Using the aforementioned GetAllRegistrationsAsync method, we checked that the device problems are correctly registered on Azure and have the correct tags and templates.

We were able to identify the device tokens of problem devices from Azure registrations. We used a PHP script that communicates directly with APNS to send notifications only to problem devices using their device tokens. Each time the device receives this notification with direct sending. These are only Azure notifications that are unreliable.

When we look at the Azure notification hub monitoring page, we see these metrics from the last 24 hours:

  • 967 successful APNS notifications
  • 3 bad channel APNS errors
  • 2 APNS Channel Expired Errors
  • 4 APNS errors

... and no other errors reported for APNS or for Azure in general. The failure rate that we see should have been an error counter of more than 20.

We were unable to determine which device tokens were responsible for the errors; is there any way to get this information from Azure?

We cannot explain why we can send notifications directly to these devices on top of APNS themselves, but not through Azure, and why Azure does not report more errors than it does.

Any suggestions or ideas?

+6
source share
1 answer

It is possible that your database has sandbox descriptor tokens (I'm not sure if device tokens are stored on your server or in the Azure Notification Hub). If you try to send a notification using a sandbox device token to the production push environment, Apple will return an InvalidToken error, and the connection is closed.

Very often, by the time the server sending push notifications to the Apple APN server receives an error response, it has already sent many more notifications (possibly with valid tokens), and all of them are discarded by Apple. At this stage, new notifications are received by Apple only after a new connection to APNS is established, therefore messages that were sent after an invalid token to the old connection should be resent. Azure may not be able to handle this resubmission correctly.

As you said, the Azure notification hub monitoring page displays a few errors. I suspect that 3 APNS Bad Channel Errors means invalid device tokens. I donโ€™t know how many invalid device tokens you actually have in the database, but even one can cause many notifications with valid tokens that Apple will not accept.

The best solution is to check all the device tokens in the database and find out those that are invalid and delete them.

+5
source

Source: https://habr.com/ru/post/971685/


All Articles