带棱镜的表单:应用程序窗口应具有根VC [英] Forms with Prism: Application windows are expected to have a root VC

查看:76
本文介绍了带棱镜的表单:应用程序窗口应具有根VC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在新应用程序中实现了Prism库,并且正在使用NavigationService.它在Android上运行良好,但是当我尝试在联网的Mac上调试Xamarin Forms iOS App时,我的Main方法会引发以下异常:

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 + 

我的主要方法是:

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:

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应用程序:

Forms App:

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

任何帮助将不胜感激.我拥有Xamarin,Xamarin Forms,Prism和Visual Studio的最新更新,但不确定是什么问题.

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.

推荐答案

您的LaunchPage引发了异常.更新OnInitialized使其看起来像这样:

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);
    }
}

这应该至少可以帮助您确定异常是什么.没有看到您的项目很难说,但是我可能会猜测您正在使用IPlatformInitializer并在Android而非iOS上注册了某些东西,或者您依赖于Xamarin Forms Dependency Service,并且该依赖关系存在于Android而不是iOS上.

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.

这篇关于带棱镜的表单:应用程序窗口应具有根VC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆