thudugala / Plugin.LocalNotification

The local notification plugin provides a way to show local notifications from .Net MAUI and Xamarin Forms apps .
MIT License
425 stars 68 forks source link

NotificationActionTapped Only Returns ReturningData From Last-Added Notification #365

Open meisam-dehghan opened 1 year ago

meisam-dehghan commented 1 year ago

I'm using V. 10.1.3 in a .Net Maui application.I add two notifications all at once with each having a different kind of ReturningData,but no matter which notification I tap in the Notification center,just the ReturningData of the last-added notification is returned.I think it's a bug,which needs to be fixed. The same issue as in: #312 ,but the problem still persists even though it's been closed! Also take a look at the following Discussion:

I will try to be clear as possible.

I am testing the plugin and everything is really clear and simple to this point. But I have a problem with the NotificationActionTapped event.

In my testing app I created two NotificationRequest with different NotificationId, Title, description, etc. I show the two notifications. The two notifications are send and I can tapped them. Their is notification 1 who is show first and notification 2 who is show second.

When I tapped notification 1 or 2, its always the data of the last show notification that its received. I cannot acces the data of the first show notification.

Code exemple to help understand what I am trying to explain

I create the two notification

            var notification1 = new NotificationRequest
            {
                BadgeNumber = 1,
                Title = "Title 1",
                Description = "Description 1",
                ReturningData = "Data 1",
                NotificationId = 1,
                Schedule =
                {
                    NotifyTime = DateTime.Now.AddSeconds(5)
                },
            };

            var notification2 = new NotificationRequest
            {
                Android =
                {
                    Priority = AndroidPriority.High,
                },

                BadgeNumber = 1,
                Title = "Title 2",
                Description = "Description 2",
                ReturningData = "Data 2",
                NotificationId = 2,
                Schedule =
                {
                    NotifyTime = DateTime.Now.AddSeconds(5)
                },
            };

            LocalNotificationCenter.Current.Show(notification1);
            LocalNotificationCenter.Current.Show(notification2);

A little Display to show the received data after the tapped notification

        LocalNotificationCenter.Current.NotificationActionTapped += Current_NotificationActionTapped;

        private void Current_NotificationActionTapped(Plugin.LocalNotification.EventArgs.NotificationActionEventArgs e)
        {
            LocalNotificationCenter.Current.GetDeliveredNotificationList();

            App.Current.MainPage.DisplayAlert(e.Request.Title, e.Request.Description, "ok");
        }

The display is alway the data from the second notification

image

Is it by design or there is something I'm doing wrong?

Thank you!

Originally posted by @AlexForget in https://github.com/thudugala/Plugin.LocalNotification/discussions/359

chyzy commented 1 year ago

Same problem exists in all 10.X.X versions in Xamarin.Forms

peter-bozovic commented 1 year ago

Still testing, but it seems in my case that everything works fine in the release build of the app !

Maybe it's also related to the PendingIntentFlag that I'm using: PendingIntentFlags = AndroidPendingIntentFlags.OneShot | AndroidPendingIntentFlags.Immutable,

In any case, in debug mode, I still get the last ReturningData, and not the one that was supposed to be related to the notification that was tapped ...

thudugala commented 1 year ago

@peter-bozovic @chyzy @meisam-dehghan

Please try version 10.1.4

peter-bozovic commented 1 year ago

The issue persists in 10.1.4 :(

I'm still getting ReturningData only from the last notification, for any previous notification that I tap ...

thudugala commented 1 year ago

@peter-bozovic are you testing with .Net Maui or Xamarin Forms?

meisam-dehghan commented 1 year ago

@peter-bozovic are you testing with .Net Maui or Xamarin Forms?

I'm using it in a .Net Maui app

thudugala commented 1 year ago

@meisam-dehghan Can you please attach a sample project?