react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

firebase.messaging().onMessage isn't triggered

Open victormarcel opened this issue 8 years ago • 7 comments

i am trying to received data messages on my app react-native using firebase.messaging().onMessage, i am sending messages through firebase console, but the messages is not calling onMessage method.

i am trying like this

constructor(props){
        super(props);
        this.onMessageListener();
}

onMessageListener = firebase.messaging().onMessage(message => console.log("mensagem enviada"))

"react-native": "0.55.4", "react-native-firebase": "^4.3.8",

victormarcel avatar Sep 08 '18 14:09 victormarcel

Have same issue

aaalive avatar Sep 10 '18 15:09 aaalive

I'll assume you are using the fcm token to target the message to a single device. What versions of firebase-core and firebase-messaging are you using?

I also have the same issue, I noticed It worked when I had the app on background even though In the documentation the following code is proposed for foreground.

componentWillUnmount() {
    this.messageListener();
}

To me it seems weird that this method just gets called on the ComponentWillUnMount for the component... maybe this behavior is expected?

kimberlyluna avatar Sep 10 '18 16:09 kimberlyluna

@aaalive, i solved this issue. So, my problem was that i was sending messages through firebase console, but the messages sent from there are notifications, calling the method:

firebase.notifications().onNotification((notification: Notification) => {
    // Process your notification as required
});

For sending messages, read this documentation. Using the FCM admin, you can send messages to devices using fcm token.

victormarcel avatar Sep 10 '18 16:09 victormarcel

@kimberlyluna , i am using this versions:

implementation "com.google.firebase:firebase-core:16.0.1"
implementation "com.google.firebase:firebase-messaging:17.1.0"

victormarcel avatar Sep 10 '18 16:09 victormarcel

Thank you for your answer. None of the call back of this lib called unfortunately. I'm trying to understand at the moment may be this watchman.. or so

On Mon, Sep 10, 2018, 7:29 PM Victor Marcel Gomes [email protected] wrote:

@aaalive https://github.com/aaalive, i could fix this issue. So, my problem was that i was sending messages through firebase console, but the messages sent from there are notifications, calling the method:

firebase.notifications().onNotification((notification: Notification) => { // Process your notification as required });

For sending messages, read this documentation https://firebase.google.com/docs/cloud-messaging/admin/send-messages. Using the FCM admin, you can send messages to devices using fcm token.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/invertase/react-native-firebase/issues/1473#issuecomment-419975782, or mute the thread https://github.com/notifications/unsubscribe-auth/AWF0p3nng1hjMdZu--1vwhmOrlQNrJOFks5uZpNpgaJpZM4Wf4jV .

aaalive avatar Sep 10 '18 17:09 aaalive

Solved issue by using react-native-firebase notifications module, instead of messaging

Strate avatar Oct 02 '18 13:10 Strate

I've not tried your solution but if the FCM console messages are only caught by onNotification listener, then why firebase official example for JS catches FCM console messages with onMessage ?

ErAz7 avatar Sep 30 '19 07:09 ErAz7