应用临危使用GCM重装后重复通知 [英] App recieves duplicate notification using GCM after reinstalling

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

问题描述

我目前正在使用GCM发送通知给用户,目前我还在学习,我怎么能最大化。现在我只使​​用提供了这里的文件 样本项目,我用的是GCM客户端样本来进行这项工作。

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.

现在利用这个混帐项目我试着把消息使用由应用程序创建的注册ID,并是它成功地将邮件传递。

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.

现在的问题是,在我卸载该应用程序。当我重新安装它会生成一个新的注册ID,其中我将其存储在服务器上加上previous人,除了我不能标注的previous登记ID来不会再收到任何消息,因为卸载可能发生在用户没有互联网连接。从那以后,我将消息发送两个注册ID的也就是ID卸载应用程序,并重新安装应用程序后,ID之前。发生什么事是我收到两个推送消息eventhough我预期它只有一次,因为应用程序已经改变注册ID。

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.

我想到的是,应用程序可能会收到twoor多个重复的应用程序如果有的话我也更新应用程序,因为文件上的表示,注册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?

推荐答案

从官方文档:

<一个href="https://developers.google.com/cloud-messaging/registration#how-uninstalled-client-app-unregistration-works"相对=nofollow>客户端应用程序如何卸载注销工作

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. 在最终用户卸载客户端应用程序。
  2.   
  3. 在该应用程序服务器发送消息给GCM连接服务器。
  4.   
  5. 的GCM连接服务器将邮件发送到设备上的GCM客户端。
  6.   
  7. 在该设备上的GCM客户端接收消息并检测到客户端应用程序已被卸载;检测细节取决于它的客户端应用程序运行的平台。
  8.   
  9. 在该设备上的GCM客户端通知GCM连接   该客户端应用程序卸载服务器。
  10.   
  11. 的GCM连接服务器   标记为删除的注册标记。
  12.   
  13. 在该应用程序服务器发送一个   消息GCM。
  14.   
  15. 的GCM返回NotRegistered错误消息   应用服务器。
  16.   
  17. 在该应用程序服务器应删除注册标记。
  18.   
  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.

请注意   这可能需要一段时间进行注册令牌是完全   从GCM中删除。 因此,有可能是在步骤7发送的邮件   以上获得有效的消息ID作为响应,即使该消息   将不会被传递到客户端应用程序。最终,登记   令牌将被删除,服务器将得到一个NotRegistered错误,   没有任何进一步的行动被要求从应用程序服务器。

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.

但是,它显然可以发生,你仍然会得到通知旧注册ID,因为用户状态的其他问题:

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

  • Android的GCM和多个令牌
  • <一个href="http://stackoverflow.com/questions/27845298/gcm-deleting-app-and-reinstalling-multiple-notifications">GCM删除应用程序,并重新安装。多个通知
  • <一个href="http://stackoverflow.com/questions/16320549/unregistering-and-re-registering-for-gcm-messages-causes-two-regids-to-be-valid">Unregistering并重新注册为GCM的消息引起两个REGID的是有效的。难道这是故意的吗?
  • <一个href="http://stackoverflow.com/questions/17328654/do-old-gcm-tokens-live-on-even-after-an-uninstall">Do老GCM令牌即使卸载后生活呢?
  • Android GCM and multiple tokens
  • GCM deleting app and reinstalling. Multiple Notifications
  • Unregistering and re-registering for GCM messages causes two regId's to be valid. Is this as intended?
  • Do old GCM tokens live on even after an uninstall?

有关这个问题,有一种所谓的规范的ID功能性:

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.

实施规范的标识可以帮助你更轻松地从这些恢复   的情况。 :一种规范的注册ID是注册令牌   最后登录客户端应用程序请求。这是ID   这将消息发送到设备时,该服务器应该使用。

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.

如果您尝试使用旧的注册令牌发送一条消息,GCM会   处理请求和往常一样,但它包括将在规范化的ID   响应的registration_id字段。 确保更换   注册标记存储在您的服务器与此规范的ID,如   最终老注册令牌将停止工作。

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天全站免登陆