通过取消注册限制GCM / FCM通知 [英] Restricting GCM/FCM notifications through unregister

查看:542
本文介绍了通过取消注册限制GCM / FCM通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法限制Firebase推送通知注册?不寻找主题。比方说,我有一个登录功能。我想登录用户订阅推送通知。然后令牌可以发送到服务器并存储。



在用户注销的同时,用户也应该注销。



那么目前有没有可用的机制?我检查了Firebase API文档,但找不到任何内容。



只是想知道我是否遗漏了任何东西。


<为什么要使用 deleteToken() vs deleteInstanceId() / code>,请参阅此回答






注销注销应用程序实例(设备/用户)是不可取的,因为甚至是GCM。根据 GCM文档


开发人员不应该注销客户端应用程序作为注销或用户之间切换的机制,原因如下:


  • 注册令牌不与特定的登录用户相关联。如果客户端应用程序取消注册,然后重新注册,应用程序可以收到相同的注册令牌或不同的注册令牌。


  • 取消注册和重新注册花费五分钟来宣传。在此期间,由于未注册状态,邮件可能会被拒绝,并且邮件可能会发送给错误的用户。


如果您仍想继续操作,则仍然可以参考上述相同的文档。


取消注册和取消订阅



客户端应用程序可以使用三种方法停止从应用程序服务器接收消息和/或主题订阅:




  • InstanceID deleteToken()将受众设置为应用服务器的发件人ID并将范围设置为GCM。这会停止来自特定应用服务器的消息(包括主题消息)。


  • InstanceID deleteID()。这将停止所有应用服务器的所有以前的注册和主题订阅的消息


  • GCMPubSub unsubscribe()。这会停止来自应用服务器特定主题的主题消息



对于FCM,它应该是 FirebaseInstanceId


Is there a way to restrict Firebase push notification registration? Not looking for topics. Let's say I have a login function. I want signed in users to be subscribed for push notifications. Then token can be sent to server and stored.

At the same time when users log out, user should also be unregistered.

So is there a mechanism available currently? I went through the Firebase API documentation but I could not find anything on that.

Just want to know whether I have missed anything.

解决方案

For the difference on when to use deleteToken() vs deleteInstanceId(), refer to this answer.


Unregistering an app instance (device/user) on logout is not advisable since even GCM. As per the GCM docs

Developers should never unregister the client app as a mechanism for logout or for switching between users, for the following reasons:

  • A registration token isn't associated with a particular logged in user. If the client app unregisters and then re-registers, the app can receive the same registration token or a different registration token.

  • Unregistration and re-registration may each take up to five minutes to propagate. During this time messages may be rejected due to the unregistered state, and messages may go to the wrong user.

If you still want to proceed, you can still refer to the same docs above.

Unregistration and Unsubscription

There are three methods a client app can use to stop receiving messages and/or topic subscriptions from the app server:

  • InstanceID deleteToken() with audience set to the app server's sender ID and scope set to GCM. This stops messages (including topic messages) from a specific app server

  • InstanceID deleteID(). This stops messages from all previous registrations and topic subscriptions for all app servers

  • GCMPubSub unsubscribe(). This stops topic messages from the specific topic of the app server

For FCM, it should be the FirebaseInstanceId.

这篇关于通过取消注册限制GCM / FCM通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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