应用程序在重新安装后使用GCM接收到重复通知 [英] App receives duplicate notification using GCM after reinstalling

查看:155
本文介绍了应用程序在重新安装后使用GCM接收到重复通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用GCM向用户发送通知,目前我仍在研究如何将其最大化。现在我只使用文档此处提供的示例项目,并使用gcm-client示例来处理它。



现在使用来自Git的项目我尝试使用应用程序创建的注册ID推送消息,并且它已成功传递消息。



现在问题是我卸载应用程序后。重新安装后,它会生成一个新的注册ID,我将它与前一个一起存储在服务器上,不同的是我不能标记以前的注册ID以便不会收到任何进一步的消息,因为当用户没有互联网时卸载可能发生连接。之后,我会在重新安装应用程序之后,将消息发送到两个注册ID(它是卸载应用程序之前的ID)和ID。发生什么事是我收到了两条推送消息,尽管我预料它只会得到一条消息,因为应用程序已经更改了注册ID。



我预计应用程序可能会收到更多重复的应用程序,如果有的话,我也更新了应用程序,因为在文档上说注册ID可能会更新。



我可以做任何解决方法来处理这些重复的消息?

解决方案

如何卸载客户端应用程序取消注册的工作原理

在卸载
后,客户端应用程序可以自动取消注册。但是,这个过程不会立即发生。
在这种情况下发生的
是:
$ b


  1. 最终用户卸载客户端应用程序。

  2. 应用服务器向GCM连接服务器发送消息。

  3. GCM连接服务器将消息发送至设备上的GCM客户端。

  4. 设备上的GCM客户端收到消息并检测到客户端应用程序已被卸载;检测细节取决于客户端应用程序运行的平台。

  5. 设备上的GCM客户端通知GCM连接
    服务器客户端应用程序已卸载。

  6. GCM连接服务器
    标记要删除的注册标记。

  7. 应用服务器向GCM发送
    消息。

  8. GCM向
    应用服务器返回一个NotRegistered错误消息。

  9. 应用服务器应删除注册令牌。

请注意
,注册令牌可能需要一段时间才能完全从GCM中删除
。因此,即使消息
不会传递到客户端应用程序,也可能在上面的步骤7
中发送的消息获得有效的消息ID。
最终,注册
令牌将被删除,服务器将收到NotRegistered错误
,而不需要从应用服务器进一步采取任何行动。

但是,显然您仍然会收到旧注册ID的通知,因为用户在其他问题中声明:



对于这个问题,有一个名为canonical IDs的功能:


Canonical IDs

客户端应用程序触发
相同设备的多个注册,它可能很难协调状态,客户端应用程序
可能以重复消息结束。



实现规范ID可以帮助您更轻松地从这些
情况中恢复。 规范注册ID是客户端应用程序请求的最后一次注册
的注册令牌。这是服务器在将消息发送到设备时应使用的ID



如果您尝试使用旧注册令牌,GCM将
像往常一样处理请求,但它将在响应的registration_id字段中包含
中的规范ID。 确保使用此规范ID替换服务器中存储的
注册令牌,因为
最终会使旧注册令牌停止工作。



I'm currently trying to use GCM to send notification to user and currently I'm still studying on how I can maximize it. For now I just use the sample project provided on the documentation here and I use the gcm-client sample to work on it.

Now using this project from Git I tried to push a message using the registration ID created by the app and yes it successfully delivers the message.

Now the problem is that after I uninstalled the application. After I reinstall it it will generate a new registration ID wherein I store it on a server together with the previous one except that I can't tag the previous registration ID to not receive any further message since the uninstall might happen when user has no internet connection. After that I send a message to two registration ID's which is the ID before uninstalling the app and the ID after reinstalling the application. What happen is that I receive two push messages eventhough I expected it to only get one since the app already changes the registration ID.

I expect that the app might receive twoor more duplicate apps if ever I also updated the app since as said on documentation the registration ID might change on update.

Any workaround I can do to handle this duplicate messages?

解决方案

From the official documentation:

How uninstalled client app unregistration works

A client app can be automatically unregistered after it is uninstalled. However, this process does not happen immediately. What happens in this scenario is:

  1. The end user uninstalls the client app.
  2. The app server sends a message to GCM connection server.
  3. The GCM connection server sends the message to the GCM client on the device.
  4. The GCM client on the device receives the message and detects that the client app has been uninstalled; the detection details depend on the platform on which the client app is running.
  5. The GCM client on the device informs the GCM connection server that the client app was uninstalled.
  6. The GCM connection server marks the registration token for deletion.
  7. The app server sends a message to GCM.
  8. The GCM returns a NotRegistered error message to the app server.
  9. The app server should delete the registration token.

Note that it might take a while for the registration token to be completely removed from GCM. Thus it is possible that messages sent during step 7 above get a valid message ID as a response, even though the message will not be delivered to the client app. Eventually, the registration token will be removed and the server will get a NotRegistered error, without any further action being required from the app server.

However, it can apparently happen that you still get the notification for the old registration ID, as users state in other questions:

For this problem, there is a functionality called "canonical IDs":

Canonical IDs

If a bug in the client app triggers multiple registrations for the same device, it can be hard to reconcile state and the client app might end up with duplicate messages.

Implementing canonical IDs can help you more easily recover from these situations. A canonical registration ID is the registration token of the last registration requested by the client app. This is the ID that the server should use when sending messages to the device.

If you try to send a message using an old registration token, GCM will process the request as usual, but it will include the canonical ID in the registration_id field of the response. Make sure to replace the registration token stored in your server with this canonical ID, as eventually the old registration token will stop working.

这篇关于应用程序在重新安装后使用GCM接收到重复通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆