Android C2DM:向同一设备和应用程序重复消息

发布于 2024-11-19 02:30:56 字数 303 浏览 5 评论 0原文

我想知道是否有人在使用 Google C2DM 时遇到过这个问题?这是我面临的场景:

  1. 用户安装应用程序并注册 与C2DM服务器进行注册 钥匙。
  2. 用户卸载应用程序。
  3. 用户重新安装应用程序(并且 向 C2DM 服务器注册新的 注册密钥)。

现在,我从服务器向用户的手机发送消息,他们收到重复的消息。

任何人都可以深入了解这是否是预期的行为或者我如何解决它? 谢谢,

I'm wondering if anyone has faced this issue with Google C2DM? This is the scenario I am faced with:

  1. User installs the app and registers
    with C2DM server for a registration
    key.
  2. User uninstalls the app.
  3. User reinstalls the app (and
    registers with C2DM server for new
    registration key).

Now I send message from my server to the user's phone and they get a duplicate message.

Could anyone shed any insight into wether this is expected behaviour or how I can fix it?
Thanks,

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

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

发布评论

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

评论(5

り繁华旳梦境 2024-11-26 02:30:56

不确定这是否是最好的方法,但在 <一个 href="https://groups.google.com/forum/#!forum/android-c2dm">android-c2dm 小组,海报提供了一种技术:

我在消息中发送注册 ID,以便我可以根据设备上存储的注册 ID 进行检查。

如果不相同,则丢弃它并通知服务注册 ID 不再使用

缺点是发送注册 ID 已经占用了一些空间
消息大小有限。但在我的情况下效果很好,因为我
原始消息的长度不超过几个字符。

Not sure if this is the best approach, but there's a relevant thread over at the android-c2dm group, where the poster offers one technique:

I am sending registration id in the message, so I can check it against the stored registration id on the device.

If it's not the same, discard it and notify the service that registration Id is no longer in use

Downside is sending registration Id takes up some space in already
limited message size. But works perfectly in my case since my
original message is no more than a few chars long.

﹂绝世的画 2024-11-26 02:30:56

这种情况应该只发生在重新安装应用程序后的第一个推送通知中。

在检测已卸载的应用程序时,Google C2DM 服务以被动模式工作。

卸载应用程序后的首次推送通知(无需从 C2DM 注销!!!)不会返回任何错误响应。但是,第二个推送通知将返回“无效注册”或“未注册”错误代码,您可以在其中意识到应用程序已被卸载。

原因是C2DM服务器立即返回响应代码,然后才尝试推送客户端。当客户端响应应用程序已卸载时,该应用程序将从 C2DM 服务器中删除。下一次推送尝试将立即返回错误代码。

This should only happen for the first push notification after re-installing your application.

Google C2DM service is working in passive mode when it comes to detecting uninstalled applications.

First push notification after uninstalling your application (without unregistering from C2DM!!!) will NOT return any error in response. However, the second push notification will return an "invalid registration" or "not registered" error codes where you can realize the application was uninstalled.

The reason is that C2DM servers return the response code immediately and only then tries to push the client. When client respond that an application was uninstalled, it is deleted from C2DM servers. Next push attempt will return an error code immediately.

红ご颜醉 2024-11-26 02:30:56

另一种解决方案可能是为您的服务器提供设备的唯一标识符。在这种情况下,当设备在重新安装后尝试注册时,您只需更新该 UUID 的注册 ID 即可。

Another solution could be to provide your server with a unique identifier for the device. In that case you can just update the registrationID for that UUID when the device tries to register after re-installation.

北方。的韩爷 2024-11-26 02:30:56

是的,我遇到了同样的问题,在我看来,这是 Android C2DM 实现中的一个重大疏忽。 iOS 可以更好地处理这一问题,因为应用程序只能接收一个且仅一个设备令牌(相当于 c2dm 注册 ID)的通知。

我使用的解决方法是将注册 ID 的最后 10 个字符作为 c2dm 负载的一部分发送然后在我的 onMessage 方法中进行以下检查:

    if (!regId.endsWith(bundle.getString("regsuffix"))) return null;

Yup, I've run into the same issue and in my opinion it's a big oversight in the Android C2DM implementation. iOS handles this much better in that an app can only ever receive notifications for one and only one device token (equivalent of the c2dm registration id)

The workaround I use is to send the last 10 characters of the registration id as part of the c2dm payload and then in my onMessage method I do the following check:

    if (!regId.endsWith(bundle.getString("regsuffix"))) return null;
旧瑾黎汐 2024-11-26 02:30:56

@Zamel 和 @johan 的答案都很好,需要结合起来。如果将这两种解决方案结合起来,您将最大限度地减少服务器的数据库。

因此,最好的解决方案是:

  1. 在将推送令牌发送到服务器时发送设备 ID

  2. 在为现有设备 ID 发送时更新推送令牌

  3. 如果推送通知向服务器返回“无效注册”或“未注册”错误代码,则使服务器数据库中的推送令牌无效

当推送令牌被识别为“无效注册”时”或“未注册”您可以使其无效(将其标记为空)、删除数据库中的行或实现过期功能。这取决于您的需求

Both @Zamel and @johan answers are good and need to be combined. If you combine both solutions than you will minimize your server's database.

So the best solution will be to:

  1. Send device id when sending the push token to the server

  2. Update push token when is sent for existing device id

  3. Invalidate push token in the server's database, if push notification returns an "invalid registration" or "not registered" error codes to the server

When push token is recognized as "invalid registration" or "not registered" you can invalidate it(mark it as null), delete the row in the database or implement expiration functionality. It depends on your needs

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