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;