I try to get react-native-firebase
v6 to work in my app. I use React Native 0.59.10.
I have installed react-native-firebase
v6 according to the documentation. It didn't specify about adding service MyFirebaseMessagingService
into the AndroidManifest.xml
unlike in v5 so I didn't do it. Afterwards, the app didn't receive any notification while in foreground but did receive them while in background.
I tried to add MyFirebaseMessagingService
into AndroidManifest.xml
like so:
<service
android:name=".java.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
There was some sort of a progress. The app crashed immediately after I sent a notification from Firebase console. Hence, I knew the app was aware of incoming notification but somehow crashed.
Below is my code to import and initialize a listener.
import messaging from '@react-native-firebase/messaging';
import { Alert } from 'react-native';
// Initialize notifications
const init = () => {
try {
messaging().onMessage((message) => {
Alert.alert('Received', JSON.stringify(message));
});
} catch (err) {
Alert.alert('Error', err.message);
}
};
In summary, I expect to receive a notification while the app is in foreground but nothing happens if I don't add MyFirebaseMessagingService
to AndroidManifest.xml
. If I add it, the app will crash on receiving notification.