Skip to content

Two notification when use firebase v6 with react-native-push-notification #3526

@enesozturk

Description

@enesozturk

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;

  1. 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 getInitialNotification not returning the notification message, it returns null
  1. Background State: Same with Quit State. Just displayed in status bar. When I press the notification, remoteMessage is null in getInitialNotification
  2. 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.

Screen Shot 2020-04-23 at 14 03 56

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.

Screen Shot 2020-04-23 at 14 39 07

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/A

firebase.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/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.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-firebase version you're using that has this issue:
    • e.g. 6.4.0
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • N


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: StaleIssue has become stale - automatically added by Stale botplugin: messagingFCM only - ( messaging() ) - do not use for Notifications

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions