Xamarin ios:应用程序在启动画面后中断

时间:2018-02-15 14:46:09

标签: xamarin.forms xamarin.ios

在我的xamarin表单项目中,我第一次运行我的xamarin ios部分,但得到以下异常:

  

已抛出Foundation.MonoTouchException   抛出Objective-C异常。名称:NSInternalInconsistencyException原因:无法实例化UIApplication委托实例。没有加载名为AppDelegate的类。

截图: enter image description here

AppDelegate.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Foundation;
    using UIKit;

    namespace Myapp.iOS
    {
        // The UIApplicationDelegate for the application. This class is responsible for launching the 
        // User Interface of the application, as well as listening (and optionally responding) to 
        // application events from iOS.
        [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();
                LoadApplication(new App(""));

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

Main.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Foundation;
    using UIKit;

    namespace Myapp.iOS
    {
        public class Application
        {
            // This is the main entry point of the application.
            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");
            }
        }
    }

提前致谢

1 个答案:

答案 0 :(得分:0)

我通过将AppDelegate.cs的Build Action属性设置为Combile

来解决此问题