为什么Android C2DM推送消息总是不到达?

发布于 2024-12-02 08:40:08 字数 485 浏览 1 评论 0原文

我已经构建了一个功能正常的 C2DM 应用程序,通常它运行得很好,并且推送消息到达得很快。然而,我发现当我第一次启动应用程序或将其重新聚焦时,消息经常不会到达。

它们肯定发送成功(我收到 200 响应),并且消息格式肯定是正确的(稍后发送相同的消息效果很好)。故障可能会持续几分钟,然后突然再次开始工作,并在此后持续工作。

然而,即使在它开始工作之后,较旧的消息显然已经消失并且从未到达。消息肯定没有到达 - 我有大量的日志记录,突出显示任何到达的 C2DM 消息。

我完全清楚 C2DM 永远不会保证交付,因此我预计某些消息会失败,但根据我的经验,在某些情况下,它就是行不通。我显然想了解这是否是我在我的应用程序或 C2DM 服务本身中做错的事情。

哪些原因会导致C2DM消息传递失败? 如果消息无法传递,为什么 C2DM 服务器不从其队列中再次尝试? 相关 - 我应该仅在应用程序第一次启动时获取新的注册 ID,还是每次应用程序启动时刷新它?我目前执行后者(在应用程序中,而不是活动中)。

I've built a functioning C2DM app and generally it works very well, and the push messages arrive fast. However I find that fairly regularly when I first start the app or bring it back to focus, messages do not arrive.

They are definitely sent successfully (I get a 200 response) and the message format is certainly right (sending the same message later works fine). The failure can last for a small number of minutes, and then suddenly it starts working again, and works consistently thereafter.

However even after it starts working, the older messages have apparently disappeared and never arrive. The messages are definitely not arriving - I have extensive logging that highlights any C2DM messages that arrive.

I'm fully aware that C2DM will never guarantee delivery, so I expect some messages will fail, but in my experience, on some occasions, it just doesn't work. I obviously want to understand if that is something I am doing wrong in my app, or the C2DM service itself.

What could cause C2DM to fail to deliver messages?
If messages cannot be delivered, why is the C2DM server not trying again from its queue?
Related - should I get a new Registration ID only when the app starts the first time, or refresh it each time the app starts? I currently do the latter (in the Application, not an Activity).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清秋悲枫 2024-12-09 08:40:08

我意识到我犯了一个小学生的错误。每次应用程序启动时,我都会重新注册 C2DM。该过程有时需要相当长的时间,在此期间应用程序将不会收到发送到旧注册 ID 的推送消息。这就解释了为什么推送消息在启动应用程序后特别容易无法立即收到。

解决方案是确保仅当应用程序还没有注册 ID 时才请求注册 ID。推送消息现在工作得更加可靠。

I realised I made a schoolboy error. I was re-registering with C2DM every time the app started. That process sometimes takes quite a few seconds, and during that time the app will not receive push messages sent to the old registration ID. This explains why push messages were particularly likely to fail to be received immediately after starting the app.

The solution was to ensure the registration ID is only requested if the app does not already have one. Push messages are now working much more reliably.

情泪▽动烟 2024-12-09 08:40:08

这很可能是正确的行为。根本不保证消息一定能送达。更不用说瞬间了。

最有可能的情况是,您的手机与 Google 服务器之间的连接已断开,需要一段时间才能恢复。

This is most likely the correct behaviour. Messages are not guarantied to be delivered at all. Let alone instantly.

What it most likely is is that the connection between your phone and the Google servers is being dropped and it takes a little while to come back up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文