Forum Xamarin Xamarin.iOS

Xamarin Forms iOS 13 OnAppearing not called after I navigate back from platform specific code

JanWidmerJanWidmer USMember ✭✭
edited November 2019 in Xamarin.iOS

My App has currently the problem that it won't call OnAppearing() in the shared Code after navigating back from my iOS ViewController.

This works fine in iOS 12.

I am currently using:
XCode: 11.2.1
Visual Studio 2019 16.3.9
Xamarin.Forms v4.3.0.97036

In my ViewController in iOS I navigate back using:

Device.BeginInvokeOnMainThread(() => {
    NLog.LogManager.GetCurrentClassLogger().Log(LogLevel.Trace, $"Navigating back to shared Code");
    var firstController = UIApplication.SharedApplication.KeyWindow.RootViewController.ChildViewControllers.First().ChildViewControllers.Last().ChildViewControllers.First();
    var navcontroller = firstController as UINavigationController;
    navcontroller.DismissViewController(false, () => { });
});

As I said, works fine with iOS12 and previous iOS versions.

Best Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    Accepted Answer

    After iOS13, apple changes the view controller presentation style , it is not full-screen now ,so the viewWillappear(OnAppearing in Forms) would not triggered while back to that page .

    Set navigationController.modalPresentationStyle = UIModalPresentationFullScreen; should be able to solve the issue , refer https://forums.developer.apple.com/thread/119675.

    Or

    Use platform specifics in Forms project would do the trick too .
    Refer https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/ios/page-presentation-style .

  • JanWidmerJanWidmer USMember ✭✭
    Accepted Answer

    @ColeX Thank you very much. I just needed a few more minutes to think about it twice.

    I had to do this:

    void IScanOcr.ScanOcr()
            {
                var controller = new ViewController();
    
                controller.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
    
                Device.BeginInvokeOnMainThread(() =>
                {
                    // Muss auf dem Main Thread aufgerufen werden, da es einen Fehler wirft, wenn Berechtigungen angefordert werden.
                    UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(controller, false, null);
                });
            }
    

    I had to do this (of course) before I Present my controller.

    Before I did this in the OnAppearing of my Controller.

    Thanks again

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    Accepted Answer

    After iOS13, apple changes the view controller presentation style , it is not full-screen now ,so the viewWillappear(OnAppearing in Forms) would not triggered while back to that page .

    Set navigationController.modalPresentationStyle = UIModalPresentationFullScreen; should be able to solve the issue , refer https://forums.developer.apple.com/thread/119675.

    Or

    Use platform specifics in Forms project would do the trick too .
    Refer https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/ios/page-presentation-style .

  • JanWidmerJanWidmer USMember ✭✭

    @ColeX Thank you for your fast reply. I'm not really sure, where to set navigationController.modalPresentationStyle = UIModalPresentationFullScreen;

    my 2nd attempt

    (in the alternative you mentioned)

    also I don't know where to use On().SetModalPresentationStyle(UIModalPresentationStyle.FullScreen);

    I have a DependencyServiceInterface where I later call the platform specific code.

    public interface IScanOcr
        {
            void ScanOcr();
        }
    

    on iOS:

    [assembly: Dependency(typeof(ScanOcr))]
    namespace MyCompany.iOS.Dependency_Services
    {
        public class ScanOcr : IScanOcr
        {
            void IScanOcr.ScanOcr()
            {
                var controller = new ViewController();
    
                Device.BeginInvokeOnMainThread(() =>
                {
                    UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(controller, false, null);
                });
            }
        }
    }
    

    where would I use the On

  • JanWidmerJanWidmer USMember ✭✭
    Accepted Answer

    @ColeX Thank you very much. I just needed a few more minutes to think about it twice.

    I had to do this:

    void IScanOcr.ScanOcr()
            {
                var controller = new ViewController();
    
                controller.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
    
                Device.BeginInvokeOnMainThread(() =>
                {
                    // Muss auf dem Main Thread aufgerufen werden, da es einen Fehler wirft, wenn Berechtigungen angefordert werden.
                    UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(controller, false, null);
                });
            }
    

    I had to do this (of course) before I Present my controller.

    Before I did this in the OnAppearing of my Controller.

    Thanks again

  • VaibhavBangdeVaibhavBangde USMember ✭✭

    Hi @ColeX and @JanWidmer,

    I am facing a similar issue.

    I am using MvvmCross, for me the viewWillAppear is getting called every time for some time interval and after that "viewWillappear" method is not getting called for any view, not even for showing a new view.

    similar behaviour on iOS 13 simulator.

    I am using following versions :

    Visual Studio : Version 8.3.5 (build 13)
    Xamarin iOS : 13.4.0.2
    MvvmCross : 4.4.0

    Do you guys have any idea why this is happening.

    Thanks,
    -Vaibhav Bangde.

Sign In or Register to comment.