Intermittent NotificationHub delivery errors with NotificationSystemError: "InvalidToken"

I ran into a problem with NotificationHubs, where occasionally notifications cannot be delivered to an iOS client.

My notification hub is configured to use token authentication using APNS (as opposed to authenticating a legacy certificate).

I have updated the notification level for the notification level to the standard to get more information about this. In most cases, notifications (more than 95%) are correct. I added registration to track the NotificationId of each push notification that was queued with notification hubs. Then, when I was notified of the failure, I went and looked at the details for this particular notification using the following method:

var details = await notificationHub.GetNotificationOutcomeDetailsAsync("<notification id>"); 

Checking the details, I noticed that although the state was โ€œcompletedโ€ (which means that NotificationHubs received and processed the operation), PnsErrorDetailsUri was non-zero, indicating that there was a problem with the delivery of the notification:

enter image description here

Going to the PnsErrorDetailsUri value in the browser caused the following file to load:

enter image description here

Here I noticed that NotificationSystemError says there is an "InvalidToken". This token seems to be related to some under-cover messages between Azure and APNS. This is NOT NOT due to the fact that the device token registered in NotificationHubs is invalid. I checked that registerId was still in the notification hubs and pointed to the correct device. In addition, capturing the raw NotificationBody from the parts and resubmitting it using the same tag leads to the successful delivery of a new notification.

Does anyone know what an InvalidToken can say, or what could be causing these intermittent NotificationHub delivery failures?

UPDATE:

I found mention of various NotificationSystemErrors here , one of which is my InvalidToken error. However, I cannot find a description of what the actual causes of these errors are.

+5
source share
1 answer

I never had a definitive answer why the error occurred, but I seemed to be able to solve my problem.

We have 2 separate namespace / notification hubs, one for Apple production notifications and one for apple sandbox notifications. We have a switch, so the devices are registered in the correct hub. I examined all of our registrations and they all looked in the right place.

However, during this check, I noticed that many devices had a large number of registrations. Each of these registrations had an ID-ID apple PNS (which was a valid token), but it seemed strange to me that it had dozens (in one case hundreds) of the same PNS marker. Each registration identifier was the same, except that after it has a hyphen incremented number (for example, 1231231231235396312-6910179870480973035-1, 1231231231235396312-6910179870480973035-2, 1231231231235396312-6910179870480973035-3 and so on). It seems that every time I call NotificationHubClient.CreateAppleNativeRegistrationAsync, it adds a new entry without deduplication. Eliminating these duplicate elements seems to have solved the problem I am facing. It seems that NotificationHubs is sometimes confused with too many registrations associated with a device.

I ended up adding some code at my end to try and filter out duplicates at the moment. However, I would expect NotificationHubs to handle this for me ...

0
source

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


All Articles