-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Issue
Hi! I am Enes. I am developing a mobile application with react-native-firebase. I migrate my application v5 to v6 with documentation in rnfirebase.io migration to v6. Everything is fine. I got notifications in foreground, background and quit states. But the issue for me is that;
- In Quit State: Notification received.
- Problem 1: It just displaying in status bar, not from top of the phone
- Problem 2: When press the notification, launches the app but
getInitialNotificationnot returning the notification message, it returns null
- Background State: Same with Quit State. Just displayed in status bar. When I press the notification, remoteMessage is null in
getInitialNotification - Foreground State: Notification received in messaging().onMessage() method. But not displayed on status bar or anywhere else.
So I decided to use https://rnfirebase.io/migrating-to-v6 with rn-firebase v6 as you suggested here
I used PushNotification.localNotification() method. That resolved the issue little bit. But another issue happened. This time it shows me two notification in status bar. But displays the notification by the way from top.
Some code snippets from my app;
In App.js file, I use setBackgroundMessageHandler as you suggested in documentation.
const showNotification = notification => {
PushNotification.localNotification({
title: 'Title',
message: 'Body',
});
};
useEffect(() => {
messaging()
.getInitialNotification()
.then(response => {
console.log('Message handled in the getInitialNotification!', response);
if (response) showNotification(response);
});
messaging().onNotificationOpenedApp(async remoteMessage => {
console.log('Message handled in the quit state!', remoteMessage);
showNotification(remoteMessage);
});
const unsubscribe = messaging().onMessage(async remoteMessage => {
// When app in foreground
console.log('Message handled in the foregroud!', remoteMessage);
showNotification(remoteMessage);
});
return () => {
return unsubscribe;
};
}, []);and
in main index.js file
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
PushNotification.localNotification({
title: 'Title',
message: 'Notification body in setBackgroundMessageHandler',
});
});Most of the code snippets are guided from documentation. Not specific code here.
I totally messed up. Any reference and guide for this setup (react-native-firebase + react-native-push-notification) or any other suggestion would be great.
Thanks in advance.
Project Files
Javascript
Click To Expand
package.json:
# N/Afirebase.json for react-native-firebase v6:
{
"react-native": {
"messaging_android_notification_channel_id": "@string/notification_channel_id",
"messaging_android_notification_color": "@color/white"
}
}iOS
Click To Expand
ios/Podfile:
- I'm not using Pods
- I'm using Pods and my Podfile looks like:
# N/AAppDelegate.m:
// N/AAndroid
Click To Expand
Have you converted to AndroidX?
- my application is an AndroidX application?
- I am using
android/gradle.settingsjetifier=truefor Android compatibility? - I am using the NPM package
jetifierfor react-native compatibility?
android/build.gradle:
// N/Aandroid/app/build.gradle:
// N/Aandroid/settings.gradle:
// N/AMainApplication.java:
// N/AAndroidManifest.xml:
<!-- N/A -->Environment
Click To Expand
react-native info output:
OUTPUT GOES HERE
- Platform that you're experiencing the issue on:
- iOS
- Android
- iOS but have not tested behavior on Android
- Android but have not tested behavior on iOS
- Both
react-native-firebaseversion you're using that has this issue:e.g. 6.4.0
Firebasemodule(s) you're using that has the issue:e.g. Instance ID
- Are you using
TypeScript?N
- 👉 Check out
React Native FirebaseandInvertaseon Twitter for updates on the library.

