android - 即使卸载后旧的 GCM token 仍然存在吗?

标签 android google-cloud-messaging

我们一直致力于 GCM 实现,并注意到分配给应用安装的设备地址即使卸载该应用也可以继续存在。

所以我们安装了一个应用程序,获取 token A,设备订阅了特定的警报类型 1,消息 token A 非常成功。然后我们卸载应用程序。

不,我们重新安装,接收 token B,并且设备订阅了特定的警报类型 2,我们向 token B 发送消息非常成功。

现在,由于我们在卸载和重新安装应用程序之间没有向 token A 发送消息,因此我们仍然可以向两个 token 发送消息,并且应用程序都会接收到它们。

如果我们在应用卸载时尝试向 token A 发送消息,我们可以从 Google 的响应中清除它。

有什么方法可以知道 token A 在技术上不再有效?

最佳答案

来自官方文档:

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.

但是,正如用户在其他问题中所述,您显然仍会收到旧注册 ID 的通知:

对于这个问题,有一个叫做“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.

关于android - 即使卸载后旧的 GCM token 仍然存在吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17328654/

相关文章:

android - Firebase 云消息传递设备 ID : multiple user in same app in same device

javascript - GCM MismatchSenderId 原因

android - 找不到 design.jar (com.android.support :design:27. 0.0)

java - 操作栏中缺少搜索操作项

android - Gradle:applicationVariants.all 跳过一个变体

Android - 仅更改 alpha TextView 的文本

android - 对返回 when 语句感到困惑

ios - Swift gcm推送无法收到通知

java - GCM 在 2.3.6 中没有收到消息,但在 4.1.2 中没问题

android - GCM - 以编程方式注册广播接收器时获取 SERVICE_NOT_AVAILABLE