React Native:错误:[消息/未知] java.io.IOException:java.util.concurrent.ExecutionException:java.io.IOException:FIS_AUTH_ERROR

问题描述 投票:0回答:3

我正在尝试在我的应用程序中实现推送通知。我已使用

react-native-firebase/app
@react-native-firebase/messaging
库进行推送通知。我已遵循完整的文档并尝试实现推送通知。但我显示了此错误获取推送令牌错误:[消息/未知] java.io.IOException:java.util.concurrent.ExecutionException:java.io.IOException:FIS_AUTH_ERROR

代码:

import React, {Fragment, useEffect} from 'react';
import {StyleSheet, View, Text, Button} from 'react-native';
import messaging from '@react-native-firebase/messaging';

//1
const checkPermission = () => {
  messaging()
    .hasPermission()
    .then((enabled) => {
      if (enabled) {
        getToken();
      } else {
        requestPermission();
      }
    })
    .catch((error) => {
      console.log('error checking permisions ' + error);
    });
};

//2
const requestPermission = () => {
  messaging()
    .requestPermission()
    .then(() => {
      getToken();
    })
    .catch((error) => {
      console.log('permission rejected ' + error);
    });
};

//3
const getToken = () => {
  messaging()
    .getToken()
    .then((token) => {
      console.log('push token ' + token);
    })
    .catch((error) => {
      console.log('error getting push token ' + error);
    });
};

const Notification = () => {
  useEffect(() => {
    checkPermission();
    messaging().setBackgroundMessageHandler(async (remoteMessage) => {
      console.log('Message handled in the background!', remoteMessage);
    });

    
  });
  
  return (
    <View style={styles.container}>
      <Text>Push Notification</Text>
     
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  button: {
    margin: 10,
  },
});

export default Notification;
java android react-native firebase-cloud-messaging react-native-firebase
3个回答
1
投票

我也有同样的问题,你可以尝试这个解决方案:通过Android Studio打开React Native项目,查看工具栏并选择Build -> Clean Project,然后单击Run app(Macbook上的^R或control + r) 。它对我有用。


0
投票

如果您使用的是 React Native 项目,请转到文件夹 android 并在终端上尝试此命令 ./gradlew clean,与 android studio 中的 Build -> clean 项目相同。

https://docs.gradle.org/current/userguide/command_line_interface.html


0
投票

如果您使用的是 Android 模拟器,请关闭并重新打开它,这将解决您的问题!

© www.soinside.com 2019 - 2024. All rights reserved.