使用 Amazon SNS 处理 GCM Canonical Id

Handle GCM Canonical Id with Amazon SNS

我有问题。当 GCM return 规范 ID 时,我该如何处理这种情况。 我在 Whosebug 上发现了几个相同的问题,但没有解决方案。关于令牌管理的 Amazon SNS 文档说 SNS 会自动处理这种情况。当 GCM return canonical id amazon SNS 将旧令牌更新为新令牌时。但是我怎么知道呢?我有自己的数据库,其中包含所有已注册的令牌和端点。我不知道亚马逊是否更新令牌并向所有人发送通知。结果在设备上出现了很多重复的消息。

P.S。服务器必须支持一个帐户的多个设备。

请查看 http://mobile.awsblog.com/post/Tx223MJB0XKV9RU/Mobile-token-management-with-Amazon-SNS 以获取有关如何管理移动令牌的信息。

Amazon SNS 仅当您的应用已向 他们 注册时才会处理令牌管理。由于您有自己的数据库和端点,因此您必须自己管理它。

从服务器推送消息后,您将在响应中收到规范 ID。

根据 Google 的文档,

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.

最好使用推送后返回的规范 ID 更新您的注册 ID。

此外,如果您的设备收到重复的通知,这些可能会有所帮助:-

  • 这可能是由于客户端应用程序中的错误触发了同一设备的多次注册。因此,请确保同一设备没有被多次注册。

  • 此外,如果您从设备上卸载应用程序并尝试向该设备发送推送,您会从 GCM 服务器收到 NotRegistered 错误。然后你的服务器应该删除注册令牌并且不再使用该注册令牌来推送消息。

P.S。即使一个用户有多个设备,您的数据库映射也应该是这样的:- 用户的每个设备都会有一个不同的注册令牌,并且每个令牌都将映射到一个用户。 由于令牌不同,因此在用户的所有设备上接收推送的相同消息不会有问题。

希望对您有所帮助!干杯!