FirebaseMessaging.MessageReceived triggers multiple times on receiving single push notification

See original GitHub issue

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.3.43f1
  • Firebase Unity SDK version: 11.0.0
  • Source you installed the SDK: Unity Package Manager
  • Problematic Firebase Component: Cloud Messaging
  • Other Firebase Components in use: App (Core)
  • Additional SDKs you are using: None
  • Platform you are using the Unity editor on: iOS
  • Platform you are targeting: iOS
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the issue here:

When triggering a push notification through POSTMAN having the following payload with the app in foreground, the FirebaseMessaging.MessageReceived event apparently fires 4 times.

The same is observed when app is in background and notification is tapped to resume the app.

{
    "data": {
        "typ": 13,
        "s_typ": 1,
        "cid": 1000,
        "pid": "payload_id"
    },
    "notification":
    {
      "title":"NotifTitleTest1",
      "body":"NotifBodyTest1"
    },
    "content_available": true,
    "mutable_content": true,
    "to": "czCPSW2Ar0Lwrf2D9CCz1w:APA91bFQg1Fgadw71fWx9WJo6WzfqFZ-81s8_Ff5_-dQwE7w9Fu2E96cciW49BMTU3vu4hJqFZDm5SuU_ettSKURRC0rdg7TTaHaIUO-vE_WKj_rfrI03ODklUz61TTiBmdrurBD-TTK"
}

I have double checked for multiple Monobehavior instances and subscriptions and all seems fine on this regard. I am even unsubscribing wherever I am subscribing to the events.

Attached screenshot where I am logging MessageID. Logs are printed multiple times with the same MessageID: Screenshot 2023-06-19 at 6 04 33 PM

Steps to reproduce:

  • Build for iOS
  • Deploy to Xcode and build
  • Use generated token to send notifications via POSTMAN while app is in foreground
  • MessageReceived event triggers multiple times

Relevant Code: Attached main FCM helper script: RemoteNotificationReceiver.cs.zip

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Grimshadycommented, Jun 23, 2023

For now I’m using a workaround to run my code only on the first trigger

 private void OnFirebaseMessageReceived (object sender, MessageReceivedEventArgs inFirebaseArgs)
        {
            string messageID = inFirebaseArgs.Message.MessageId;
            if (!m_ReceivedPushIDs.Contains (messageID))
            {
                m_ReceivedPushIDs.Add (messageID);
                // Your logic here
            }
        }
0reactions
google-oss-botcommented, Jul 31, 2023

Since there haven’t been any recent updates here, I am going to close this issue.

@Grimshady if you’re still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android FirebaseMessaging Service onMessageReceived ...
I have tha same problem but with Firebase Messaging Topics. I recive two notification beacuase "onMessageReceived" called twice like you.
Read more >
Understanding message delivery | Firebase Cloud ... - Google
Delivery data outlines the percentage of messages that fit each of the following metrics. It is possible that a single message fits multiple...
Read more >
Cloud Messaging
Retry with exponential backoff. A server integration can send a single message to multiple topics at once. This however is limited to 5...
Read more >
Complete Guide Flutter Push Notifications with Firebase ...
Complete Guide Firebase Messaging and Local Notification for Flutter. We covered the below topics, firebase messaging setup, send ...
Read more >
Cloud Messaging
To receive messages & notifications a real device is required. The Cloud Messaging package connects applications to the Firebase Cloud Messaging (FCM) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found