【问题标题】:How to delete/unsubscribe old firebase fcm token when user will logouts from app in angular4当用户在angular4中从应用程序注销时如何删除/取消订阅旧的firebase fcm令牌
【发布时间】:2019-03-19 19:16:49
【问题描述】:

我们正在尝试在我们的 angular5 应用程序中构建通知服务。 为此,我们正在使用 google firebase 消息服务。当用户从应用程序注销时,我们遇到的问题是令牌没有刷新或应用程序没有取消订阅,所以当新用户登录并订阅新令牌时。

请帮助删除/取消订阅 angular5 中的令牌。

订阅令牌的代码。

this.messaging.getToken().then(function(this, currentToken ) {
      if (currentToken) {
        console.log(' token alredy have for this app port domain in browser current stored token no need to create and send new token');
        console.log(currentToken);
        } else {
        // Show permission request.
        console.log('No Instance ID token available. Request permission to generate one.');
        // Show permission UI.
        new MessagingService(null, null, null, null, null, null).generateAndSendTokenToServer(fdb);
      }
    }).catch(function(err) {
      console.log('An error occurred while retrieving token. ', err);
    });
    }

【问题讨论】:

  • 您对此有什么解决方案吗? ,我也遇到过类似的情况

标签: angular google-chrome firebase firebase-cloud-messaging


【解决方案1】:

在 Angular 6 上测试过这个

deleteToken() {
this.messaging.getToken()
.then(t => this.messaging.deleteToken(t) )
.then(r => console.log(r))
.catch(e => console.error(e));  
}

之后尝试生成另一个令牌在我的情况下 .onTokenRefresh 不会被自动调用,您必须显式调用 this.messaging.getToken().then(token => console.log(token ${token})) 来生成新令牌。

并确保用户已经接受了生成令牌的请求

【讨论】:

    猜你喜欢
    • 2017-04-22
    • 2020-06-03
    • 1970-01-01
    • 2021-03-07
    • 2017-06-27
    • 2021-09-07
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    相关资源
    最近更新 更多