【问题标题】:React Native : Error: [messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: FIS_AUTH_ERRORReact Native:错误:[消息/未知] java.io.IOException:java.util.concurrent.ExecutionException:java.io.IOException:FIS_AUTH_ERROR
【发布时间】:2021-09-03 17:26:21
【问题描述】:

我正在尝试在我的应用中实现推送通知。我已经使用react-native-firebase/app@react-native-firebase/messaging 库作为推送通知。我已遵循完整的文档并尝试实施推送通知。但是我显示了这个错误getting push token Error: [messaging/unknown] 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


    【解决方案1】:

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

    【讨论】:

    • 我不知道是谁给了这个大拇指。它对我来说就像一种魅力。我想给你 100 个赞,但不幸的是我只能给一个。
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      请按照以下步骤解决此问题,

      • 将 firebase 依赖项升级到 com.google.firebase:firebase-messaging:20.1.6

      • 之后从 firebase 下载 google-services.json。将其替换为当前的。

      • 如果您的 API 密钥已过期,请通过 Build &gt; Clean Project 清理项目。请

      • 将以下代码添加到您在应用程序标记的清单中声明的​​顶级应用程序类的 onCreate 中。

        FirebaseOptions options = new FirebaseOptions.Builder()
              .setApplicationId("APP ID") // Required for Analytics.
              .setProjectId("PROJECT ID") // Required for Firebase Installations.
              .setApiKey("GOOGLE API KEY") // Required for Auth.
              .build();
        FirebaseApp.initializeApp(this, options, "FIREBASE APP NAME");
        
      • 如果您正在调试,请不要忘记将调试 SHA-256 密钥添加到 firebase。

      【讨论】:

        猜你喜欢
        • 2018-07-13
        • 1970-01-01
        • 1970-01-01
        • 2020-10-16
        • 1970-01-01
        • 2022-12-22
        • 1970-01-01
        • 2020-04-22
        • 1970-01-01
        相关资源
        最近更新 更多