Splashscreen not appearing when app is open and in background in iOS

Viewed 50

I am using a Xamarin Forms application with Azure push notification. I need to redirect to a splash screen when my push notification is clicked. Android working fine. But in iOS a splash screen is not visible.

I tried the below example. But it's not hitting on the OnAppearing() method.

example

This is my splash screen code

    public Splash(string PushNotification)
    {
        PushNotificationPage = PushNotification;
        LoadSettings();
        NavigationPage.SetHasNavigationBar(this, false);
        var sub = new AbsoluteLayout {
            BackgroundColor = Code.Application.Instance.CurrentReources.SplashScreenBackground
        };

        splashImage = new Image
        {
            Source = SplashImage
        };
        AbsoluteLayout.SetLayoutFlags(splashImage, AbsoluteLayoutFlags.PositionProportional);
        AbsoluteLayout.SetLayoutBounds(splashImage, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

        sub.Children.Add(splashImage);
        if (Device.RuntimePlatform == Device.Android)
        {
            splashImage.HeightRequest = 270;
            splashImage.WidthRequest = 270;
        }
        this.Content = sub;
    }

    protected override async void OnAppearing()
    {
        (App.Current as App).OnResumeHandler += Handle_OnResumeHandler;
        base.OnAppearing();
        
        splashImage.Opacity = 0;
        await splashImage.FadeTo(1, 3000);

        Xamarin.Forms.Application.Current.MainPage = new NavigationPage(new LoginPage(PushNotificationPage));


    }

    void Handle_OnResumeHandler(object sender, EventArgs e)
    {
        Console.WriteLine("OnPauseResumeWithPage");
    }

    protected override void OnDisappearing()
    {
        (App.Current as App).OnResumeHandler -= Handle_OnResumeHandler;
        base.OnDisappearing();
    }

Also added below method to App.cs

     protected override void OnSleep()
    {
        OnSleepHandler?.Invoke(null, new EventArgs());
    }

    protected override void OnResume()
    {
        OnResumeHandler?.Invoke(null, new EventArgs());
    }
1 Answers

I don't know this is programmatically good or bad. But its work for me now. I have call OnDisappearing() method inside splash method. Its loading only if my push notification clicked. so its work for me without issue.

if(PushNotification!=null)
{
  OnAppearing();
}
Related