当用户注销 React Native 应用程序时,如何删除 Firebase Cloud Messaging Token?

zid*_*ryi 5 android ios firebase react-native firebase-cloud-messaging

我使用 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()
  }
Run Code Online (Sandbox Code Playgroud)

谢谢。

Kai*_*ash 3

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

为了react-native-firebase <= v5.x.x

firebase.messaging().deleteToken()
Run Code Online (Sandbox Code Playgroud)

用于> 5.x.x或使用@react-native-firebase/messaging

import messaging from '@react-native-firebase/messaging';

messaging().deleteToken()
Run Code Online (Sandbox Code Playgroud)

  • 这不起作用,因为即使删除令牌后,它也会再次生成相同的 FCM 令牌。 (3认同)