TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
211 stars 49 forks source link

MAUI: NotificationTapped event is not firing in foreground mode #226

Closed sreejith-pagematics closed 10 months ago

sreejith-pagematics commented 10 months ago

I am using Plugin.Firebase and Plugin.Firebase.Crashlytics packages for implementing push notification in my MAUI application. I referred this blog and it was working fine on the Android platform.

I have added the NotificationTapped event on the App.xaml.cs Constructor. This event is firing when the app is in Background or Killed modes. But the app is in foreground mode, this event is not firing. Below is my code:

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        CrossFirebaseCloudMessaging.Current.NotificationTapped += Current_NotificationTapped;
    }

    private void Current_NotificationTapped(object sender, FCMNotificationTappedEventArgs e)
    {
        try
        {
            var data = e.Notification.Data;
            //reading data from notiifcatin and opening the page
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("Exception:>>" + ex);
        }
    }
}

Is anything else we need to do for firing this event on foreground mode?

TobiasBuchholz commented 10 months ago

The NotificationTapped event is supposed to be firing when tapping the notification regardless in which mode the app is. Are you calling the FirebaseCloudMessagingImplementation.OnNewIntent(intent) method in the OnCreate and OnNewIntent methods of your MainActivity class?

You can take a look at the samples MainActivity as reference: https://github.com/TobiasBuchholz/Plugin.Firebase/blob/b6ccded2d442f38d29ac74ae3307dcc1d70d0c1b/sample/Playground/Platforms/Android/MainActivity.cs#L24

sreejith-pagematics commented 10 months ago

@TobiasBuchholz I didn't add the OnNewIntent method on MainActivity class. Now I added that and foreground notification tapping is working fine.