【问题标题】:How to delete Firebase Cloud Messaging Token when user Log-Out of the React Native application?用户注销 React Native 应用程序时如何删除 Firebase 云消息传递令牌?
【发布时间】:2020-06-03 10:04:14
【问题描述】:

我使用 React Native FCM 进行消息传递,当用户注销应用程序时,我想删除 FCM 令牌,这样用户就不会再次收到通知。

以下是我的注销代码。

_signOutAsync = async () => {
    this.logoutEvent()
    API.post('customer/auth/logout', null, {
      headers: {
        Authorization:
          'Bearer ' + (await AsyncStorage.getItem(Config.ACCESS_TOKEN))
      }
    }).then((response) => {
      console.log(response)
    })
    this.clearData()
  }

谢谢。

【问题讨论】:

    标签: android ios firebase react-native firebase-cloud-messaging


    【解决方案1】:

    只需在您的注销功能中添加以下给定代码。

    firebase.messaging().deleteToken()
    

    【讨论】:

    • 这不起作用,因为即使在删除令牌后它会再次生成相同的 FCM 令牌。
    • 如果您遇到这个问题,请参考我的解决方案。
    • 这对我不起作用,在 deleteToken 之后,登录并调用 getToken 不会让您重新登录。相反,使用 unregisterDeviceForRemoteMessages / registerDeviceForRemoteMessages 有效。见rnfirebase.io/reference/…
    【解决方案2】:
    await firebase.messaging().deleteToken();
    

    是解决方案。

    但是,如果删除后仍然得到相同的令牌,请安装 npm 包react-native-restart,然后执行以下步骤以获取新令牌

    messaging()
                .deleteToken(undefined,'*')
                .then(() => {
                    RNRestart.Restart();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-18
      • 2018-11-06
      • 2019-04-05
      • 2023-04-01
      • 2017-07-04
      • 2017-08-28
      • 2021-03-07
      • 2020-12-10
      相关资源
      最近更新 更多