且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

诊断从 Azure 通知中心到 APNS 的丢失通知

更新时间:2023-12-03 16:53:16

您的数据库中很可能有一些沙盒设备令牌(我不确定这些设备令牌是存储在您的服务器中还是存储在 Azure 通知中心).尝试向生产推送环境发送带有沙盒设备令牌的通知时,Apple 返回 InvalidToken 错误,并关闭连接.

It's quite possible that you have some sandbox device tokens in your database (I'm not sure if the device tokens are stored in your server or in Azure Notification Hub). When trying to send a notification with a sandbox device token to the production push environment, an InvalidToken error is returned by Apple, and the connection is closed.

很多时候,当向 Apple 的 APN 服务器发送推送通知的服务器收到错误响应时,它已经发送了更多的通知(可能带有有效令牌),而所有这些通知都被 Apple 丢弃了.此时,只有在与 APNS 建立新连接后,Apple 才会接受新通知,因此需要重新发送在无效令牌后发送到旧连接的消息.Azure 可能无法正确处理这种重新发送.

Very often, by the time the server that sends push notifications to Apple's APN server gets the error response, it has already sent many more notifications (possibly with valid tokens), and all of which are discarded by Apple. At this point, new notifications are accepted by Apple only after a new connection with APNS is established, so messages that were sent after the invalid token to the old connection need to be resent. It is possible Azure don't handle this resending correctly.

如您所说,Azure 通知中心监视器页面显示了一些错误.我怀疑 3 APNS Bad Channel Errors 意味着无效的设备令牌.我不知道您在数据库中实际有多少无效的设备令牌,但即使是一个也会导致许多带有有效令牌的通知不被 Apple 接受.

As you said, the Azure Notification Hub Monitor page shows 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 DB, but even one can cause many notifications with valid tokens not to be accepted by Apple.

***的解决方案是测试数据库中的所有设备令牌,找出无效的并删除它们.

The best solution is to test all the device tokens in the DB and figure out the ones that are invalid and delete them.