OneSignal / OneSignal-Xamarin-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Xamarin app with OneSignal. https://onesignal.com
Other
105 stars 50 forks source link

Onesignal.HandleNotificationOpened! The different behavior when delay added and without delay when app is closed. #139

Closed ZalesskyMaxim closed 5 years ago

ZalesskyMaxim commented 5 years ago

Description: Hi everyone. I have issue with opening a page when clicking on push notification when app is closed.

Code (delay commented):

        public App()
        {
            InitializeComponent();
            MainPage = Settings.IsTokenSet
                ? new CustomNavigationPage(new MenuPage())
                : new CustomNavigationPage(new PracticesPage());

            OneSignal.Current.StartInit(ConstantHelper.OneSignalToken)
                .InFocusDisplaying(OSInFocusDisplayOption.None)
                .HandleNotificationOpened(async (result) =>
                {
                    try
                    {
                        if (Application.Current.MainPage == null)
                        {
                            MainPage = Settings.IsTokenSet
                                ? new CustomNavigationPage(new MenuPage(true))
                                : new CustomNavigationPage(new PracticesPage());
                        }

                        if (result.notification.payload.additionalData.ContainsKey(ConstantHelper.AppointmentId) &&
                            result.notification.payload.additionalData.ContainsKey(ConstantHelper.RealName))
                        {
                            CurrentAppointment = result.notification.payload.additionalData[ConstantHelper.AppointmentId].ToString();
                            CurrentDoctorName = result.notification.payload.additionalData[ConstantHelper.RealName].ToString();

                            if (!(Current.MainPage.Navigation.NavigationStack.Last() is ConferencePage))
                            {
                                await Current.MainPage.Navigation.PopToRootAsync();
                                var conferencePage = new ConferencePage();
                                //await System.Threading.Tasks.Task.Delay(1500);
                                await Current.MainPage.Navigation.PushAsync(conferencePage);
                            }
                        }
                        await PopUpService.HideAllLoadings();
                    }
                    catch (Exception e)
                    {
                        Analytics.TrackEvent("Exception: ", new Dictionary<string, string>
                        {
                            {"Message", e.Message},
                            {"StackTrace", e.StackTrace},
                        });
                    }
                })
                .HandleNotificationReceived(notification => { })
                .EndInit();
        }

link on video: https://www.dropbox.com/s/w9p0x8rol8ei5e5/VID_20190401_124708.mp4?dl=0

Code (delay uncommented):

        public App()
        {
            InitializeComponent();
            MainPage = Settings.IsTokenSet
                ? new CustomNavigationPage(new MenuPage())
                : new CustomNavigationPage(new PracticesPage());

            OneSignal.Current.StartInit(ConstantHelper.OneSignalToken)
                .InFocusDisplaying(OSInFocusDisplayOption.None)
                .HandleNotificationOpened(async (result) =>
                {
                    try
                    {
                        if (Application.Current.MainPage == null)
                        {
                            MainPage = Settings.IsTokenSet
                                ? new CustomNavigationPage(new MenuPage(true))
                                : new CustomNavigationPage(new PracticesPage());
                        }

                        if (result.notification.payload.additionalData.ContainsKey(ConstantHelper.AppointmentId) &&
                            result.notification.payload.additionalData.ContainsKey(ConstantHelper.RealName))
                        {
                            CurrentAppointment = result.notification.payload.additionalData[ConstantHelper.AppointmentId].ToString();
                            CurrentDoctorName = result.notification.payload.additionalData[ConstantHelper.RealName].ToString();

                            if (!(Current.MainPage.Navigation.NavigationStack.Last() is ConferencePage))
                            {
                                await Current.MainPage.Navigation.PopToRootAsync();
                                var conferencePage = new ConferencePage();
                                await System.Threading.Tasks.Task.Delay(1500);
                                await Current.MainPage.Navigation.PushAsync(conferencePage);
                            }
                        }
                        await PopUpService.HideAllLoadings();
                    }
                    catch (Exception e)
                    {
                        Analytics.TrackEvent("Exception: ", new Dictionary<string, string>
                        {
                            {"Message", e.Message},
                            {"StackTrace", e.StackTrace},
                        });
                    }
                })
                .HandleNotificationReceived(notification => { })
                .EndInit();
        }

link on video: https://www.dropbox.com/s/qnqnbqll7x94qek/VID_20190401_124918.mp4?dl=0

Can some one explain me, why application work incorrect without Delay? What I doing wrong?

Environment

  1. Version Xamarin SDK 3.4.0.
  2. Version One Signal 3.2.2
rgomezp commented 5 years ago

Hello, It's difficult for us to pinpoint what could be going wrong here. But to me it looks like there's another part of your code that is setting navigation that ends up executing before or slightly after the ...PushAsync(conferencePage) line. Check the order you are calling things in and keep in mind the fact that things execute asynchronously!

rgomezp commented 5 years ago

Closing due to no response