EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

onPushTokenReceivedCallback and onMessageReceivedCallback are called twice on iOS #1736

Open kryptus36 opened 3 years ago

kryptus36 commented 3 years ago

Using NS 7.0.11, plugin version 11.1.3 I am finding both onPushTokenReceivedCallback and onMessageReceivedCallback are called twice on iOS.

Seems fine on Android.

Possibly related: https://stackoverflow.com/questions/64501709/nativescript-firebase-onmessagereceivedcallback-does-not-fire-on-ios

saibbyweb commented 3 years ago

Having the same issue, for now I am resolving it by double checking the gcm message id:

           //import at the top
           import * as application from '@nativescript/core/application';

          // array to remember received notifications per session (declare outside the callback function)  
          let receivedNotifications = []

           // beginning of the onMessageReceivedCallback
           if (application.ios) {
               const messageId = message['gcm.message_id'];
               // if already received, return
               if (receivedNotifications.includes(messageId))
                   return;
               // else remember the message id and move forward
               this.receivedNotifications.push(messageId);
               // do your stuff
           }