3

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;
vjtechno
  • 452
  • 1
  • 6
  • 16

3 Answers3

1

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.

0

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

0

If you are using Android emulator, close and re-open it, that will fix your issue!

Lakpriya Senevirathna
  • 2,488
  • 2
  • 17
  • 35