firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
819 stars 424 forks source link

FirebaseMessaging.MessageReceived triggers multiple times on receiving single push notification #1339

Closed Grimshady closed 11 months ago

Grimshady commented 1 year ago

[REQUIRED] Please fill in the following fields:

[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:

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

google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

inigoLlamosasConneqtech commented 1 year ago

Hello, any update on this subject? I am experiencing this issue on iOS 17 beta

Grimshady commented 1 year ago

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
            }
        }
inigoLlamosasConneqtech commented 1 year ago

Hello. Thanks for the snippet. However, my problem is happening on testing Firebase push notifications on our apps on iOS 17 Beta. We are getting 6 push notifications per notification, where it works fine on current iOS 16. This is the only issue I have found with a similar problem. If you know any update please let us know.

AlmostMatt commented 1 year ago

@Grimshady Can you confirm whether or not you are testing on a device using iOS 17, similar to inigoLlamosas above?

That would be helpful for us to determine whether this is a change of behaviour when using iOS 17 or if it is an issue with the firebase SDK regardless of iOS version. (iOS 17 is currently associated with XCode 15)

Grimshady commented 1 year ago

@Grimshady Can you confirm whether or not you are testing on a device using iOS 17, similar to inigoLlamosas above?

That would be helpful for us to determine whether this is a change of behaviour when using iOS 17 or if it is an issue with the firebase SDK regardless of iOS version. (iOS 17 is currently associated with XCode 15)

Hey no, this was observed on an iOS 15.2 device

a-maurice commented 11 months ago

Unfortunately I haven't been able to reproduce this across the couple of test devices that we have. Something to try would be to increase the log level with:

Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;

or LogLevel.Verbose. That will give more info in the logs, and might indicate why it is seemingly calling your callback multiple times.

google-oss-bot commented 11 months ago

Hey @Grimshady. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 11 months ago

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.