3
votes

I just implemented the Prism Library in my new application, and I'm using NavigationService. It works fine on Android, but when I attempt to debug my Xamarin Forms iOS App on a networked Mac, my Main method throws this exception:

  Unhandled Exception:

Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch
Native stack trace:
    0   CoreFoundation                      0x00000001021f2b0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010cdcf141 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001021f6cf2 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x0000000102da93b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    4   UIKit                               0x0000000105ba0be6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 3343
    5   UIKit                               0x0000000105b9d793 -[UIApplication workspaceDidEndTransaction:] + 182
    6   FrontBoardServices                  0x000000010fae35f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    7   FrontBoardServices                  0x000000010fae346d -[FBSSerialQueue _performNext] + 186
    8   FrontBoardServices                  0x000000010fae37f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    9   CoreFoundation                      0x0000000102198c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    10  CoreFoundation                      0x000000010217e0cf __CFRunLoopDoSources0 + 527
    11  CoreFoundation                      0x000000010217d5ff __CFRunLoopRun + 911
    12  CoreFoundation                      0x000000010217d016 CFRunLoopRunSpecific + 406
    13  UIKit                               0x0000000105b9c02f -[UIApplication _run] + 468
    14  UIKit                               0x0000000105ba20d4 UIApplicationMain + 159
    15  ???                                 0x0000000124f647fc 0x0 + 

My main method is so:

static void Main(string[] args)
        {
            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main(args, null, "AppDelegate");
        }

AppDelegate:

[Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {

        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            this.LoadApplication(new Core.CitizenApp());

            return base.FinishedLaunching(app, options);
        }
    }

Forms App:

protected override void OnInitialized()
    {
        this.InitializeComponent();
        NavigationService.NavigateAsync("LaunchPage");
        return;
    }

Any help would be appreciated. I have the latest updates of Xamarin, Xamarin Forms, Prism, and Visual Studio, and I'm not sure what the issue could be.

1

1 Answers

3
votes

You have an exception being thrown by your LaunchPage. Update OnInitialized to look more like this:

protected override async void OnInitialized()
{
    try
    {
        TaskScheduler.UnobservedTaskException += (sender, e) => {
            Logger.Log(e.Exception.ToString(), Category.Exception, Priority.High);
        };
        await NavigationService.NavigateAsync("LaunchPage");
    }
    catch(Exception e)
    {
        Logger.Log(e.Exception.ToString(), Category.Exception, Priority.High);
    }
}

This should help you to at least identify what the exception is. Without seeing your project it's hard to say, but I might guess that either you are using IPlatformInitializer and registered something on Android but not iOS, or you are relying on the Xamarin Forms Dependency Service and that dependency exists on Android but not iOS.