简体   繁体   中英

React Native : Error: [messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: FIS_AUTH_ERROR

I am trying to implement the push notification in my app. I have used react-native-firebase/app and @react-native-firebase/messaging libraries for the push notification. i have follow the complete document and try to implement push notification. But I have showing this error getting push token Error: [messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: FIS_AUTH_ERROR .

Code:

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;

I have the same issue, you can try this solution: open the React Native project by Android Studio, look at the toolbar and select Build -> Clean Project after that click Run app (^R or control + r on Macbook). It's working for me.

If you're on react native project, goes to the folder android and there try this command on terminal ./gradlew clean , is the same that Build -> clean project in android studio.

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

Follow the below steps to resolve this issue,

  • Upgrade firebase dependencies to com.google.firebase:firebase-messaging:20.1.6 .

  • After that download google-services.json from firebase. Replace it with the current one.

  • Clean the project by Build > Clean Project if you got API key expired. Please

  • Add following code into onCreate of your top Application class which is you declared in manifest at the application tag.

     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");
  • If you're debugging, don't forget to add the debug SHA-256 key to firebase.

Check device internet connection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM