2017-04-22 51 views
2

我刚刚在我的新应用程序中实现了Prism库,并且正在使用NavigationService。它工作正常,在Android上,但是当我试图调试我Xamarin窗体iOS应用程序的联网Mac上,我的主要方法抛出此异常:Prism的形式:应用程序窗口预计有一个根目录VC

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 :

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

窗体应用程序:

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

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

回答

0

您的LaunchPage引发异常。更新OnInitialized看起来更像是这样的:

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上。

+0

太棒了!事实证明,我的一个依赖服务实际上并不符合它的协议,尽管零构建警告。非常感谢! – Joe

+0

我应该添加,你会希望你的代码注册与容器的服务。棱镜将取消对Xamarin Forms'DependencyService'的支持 –

相关问题