1

Owning an Ionic application (cordova), I'm using this plugin to handle pushing of notifications.

I'm confused regarding the unregister function.

Reading the official GCM documentation:

You should only need to unregister in rare cases, such as if you want an app to stop receiving messages, or if you suspect that the registration ID has been compromised. In general, once an app has a registration ID, you shouldn't need to change it.

For those reasons:

  • A registration ID isn't associated with a particular logged in user. If you unregister and then re-register, GCM may return the same ID or a different ID—there's no guarantee either way.
  • Unregistration may take up to 5 minutes to propagate.
  • After unregistration, re-registration may again take up to 5 minutes to propagate. During this time messages may be rejected due to the state of being unregistered, and after all this, messages may still go to the wrong user.

So I wonder why there is the functionality of unregistering client if this is really not recommended.

Indeed, logically, by reading that, I think about implementing a custom unregister function at client side like the following pseudo-code:

function unregister() {
     deleteRegistrationIdFromServerDatabaseOnly();
} 

=> no need to unregister the client itself.

Indeed, as it exists a mapping on the server database between registrationId and userId, by just emptying the registrationId value, no message would be sent to the client any more; what is expected.
Therefore, the only way to expect notifications again would be to let the client register again.

So, I repeat, what is the need/use case of unregistering the client itself?

It's really not clear.

4

1 回答 1

4

我在这里找到了以下内容

所以我认为取消注册的唯一用途是如果你想更改你的发件人ID。我确信 id 也会在 google 服务器上占用一些资源,因此,如果您在从服务器中删除 id 后取消注册,它可能会对他们有所帮助

公共无效注销()

注销应用程序。调用 unregister() 会停止来自服务器的任何消息。这是一个阻塞调用——你不应该从 UI 线程调用它。您应该很少(如果有的话)需要调用此方法。它不仅在资源方面很昂贵,而且会使您的注册 ID 无效,您不应该不必要地更改它。更好的方法是让您的服务器停止发送消息。如果您想更改您的发件人 ID,请仅使用取消注册。

如果我们无法连接到服务器以取消注册,则抛出 IOException。

于 2015-03-15T16:44:30.067 回答