Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

I am getting two notifications for one message being sent by my server #4333

Answered by eliw00d
eliw00d asked this question in Q&A
Discussion options

I found this issue where there was the following response:

The two notifications arrive as the OS of your phone handles any Push notification which includes the notification tag.
So, for a message containing

{
 "notification": {
 "title":"Test",
 "body":"Test",
 }
}

The OS will present the user with this notification. Then either onMessage or setBackgroundMessageHandler will be triggered, depending on the application state. In both you present the user a local notification. So, it’s just natural the you currently have two notifications.

I don't currently have onMessage or setBackgroundMessageHandler and I am still seeing this issue. Any thoughts? I was previously using react-native-notifications and have uninstalled that and as far as I can tell removed any trace of it except for maybe implementation "com.google.android.gms:play-services-gcm:16.0.0".

You must be logged in to vote

Any other thoughts?

Replies: 3 comments 7 replies

Comment options

maybe try npx react-native-clean-project to make extra sure
It certainly sounds like either two payloads are coming in, or you have two handlers (either in the SDKs default behavior, or in packages you've integrated).

You must be logged in to vote
1 reply
Comment options

I gave that a try and haven't noticed any difference, unfortunately.

Comment options

Any other thoughts?

You must be logged in to vote
6 replies
Comment options

Sounds good. I will see if I can reproduce it in a smaller setting not bound to the existing project. Is there anything you can think of that we can look for that might cause this? Maybe unnecessary Gradle dependencies or something? I'll keep digging.

Comment options

multiple registration of listeners somehow is what I'd look for, either in javascript listeners or perhaps two native listeners from two firebase libraries somehow

Comment options

So, we previously used GCM and as far as I can tell the only remnant of that is implementation "com.google.android.gms:play-services-gcm:16.0.0" in our app/build.gradle. If I remove that, I don't get any notifications and instead get the following error:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzq;
	at com.google.android.gms.gcm.GcmReceiver.onReceive(Unknown Source:86)
	at android.app.ActivityThread.handleReceiver(ActivityThread.java:3788)
	at android.app.ActivityThread.access1400ドル(ActivityThread.java:219)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
	at android.os.Handler.dispatchMessage(Handler.java:107)
	at android.os.Looper.loop(Looper.java:214)
	at android.app.ActivityThread.main(ActivityThread.java:7356)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Is there a step I am missing from the installation of RNFB? I found this from the Google docs: https://developers.google.com/cloud-messaging/android/android-migrate-fcm but that should be included in RNFB, no?

Comment options

Actually, I think I figured it out. We also had react-native-intercom which had its own receiver outside of our code (which is why I couldn't find anything). They have instructions for using FCM and following that seems to have fixed the issue.

Comment options

intercom can apparently play poorly with iOS on iOS14 causing crashes on cloud message receipt. Not sure what they are doing under the covers, but I'm sure they are listening for cloud messages so I'm not surprised they were the second receiver. Glad you found it!

Answer selected by andersonaddo
Comment options

Hello guys, I think I have a solution for this.
messaging.onBackgroundMessage((payload) => {}) to messaging.setBackgroundMessageHandler(async (payload) => {})
// This will override Firebase's default behavior

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /