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

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

问题描述

有没有办法限制 Firebase 推送通知注册?不找话题.假设我有一个登录功能.我希望登录用户订阅推送通知.然后可以将令牌发送到服务器并存储.

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.

那么目前有可用的机制吗?我浏览了 Firebase API 文档,但找不到任何内容.

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.

推荐答案

deleteToken()deleteInstanceId() 的区别请参考这里 回答.

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

即使是 GCM,也不建议在注销时取消注册应用实例(设备/用户).根据 GCM 文档

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.

注销和退订

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

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

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

  • 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().这会停止来自所有应用服务器的所有先前注册和主题订阅的消息

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

GCMPubSub 取消订阅().这会停止来自应用服务器特定主题的主题消息

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

对于 FCM,它应该是 FirebaseInstanceId.

For FCM, it should be the FirebaseInstanceId.

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

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