Xamarin.forms iOS 启动后黑屏(Xamarin Visual Studio 2022)

Xamarin.forms iOS Black Screen after launching (Xamarin Visual Studio 2022)

我有一个应用程序已经开发了一段时间,我想将它“移植”到 iOS。当我启动它时,启动画面出现并且工作正常。在启动画面之后,它变成黑屏,但不会崩溃。如果我创建一个新应用程序并尝试 运行 它会完美运行。我不使用任何故事板,我正在尝试部署到 iPhone SE。它目前有 iOS 15.3。这可能是什么原因造成的?

编辑: 这是应用程序打开的第一个页面的代码:

<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Easy_Learn.Pages.Shellpage"
            xmlns:pages="clr-namespace:Easy_Learn.Pages"
            xmlns:local="clr-namespace:Easy_Learn"
            xmlns:viewtemplates="clr-namespace:Easy_Learn.ViewTemplates"
            xmlns:windows="clr-namespace:Xamarin.Forms.PlatformConfiguration.WindowsSpecific;assembly=Xamarin.Forms.Core"
            windows:Application.ImageDirectory="Assets"
            FlyoutHeaderTemplate="{DataTemplate viewtemplates:FlyoutHeader}"
            Shell.TabBarIsVisible="False"
            Shell.TabBarForegroundColor="{StaticResource backGroundColor}"
            Shell.BackgroundColor="{StaticResource backGroundColor}"
            Shell.TitleColor="{StaticResource textColor}"
            Shell.ForegroundColor="{StaticResource textColor}">
    <ShellContent ContentTemplate="{DataTemplate local:MainPage}" Title="Lernen" Icon="LightBulb.png"/>
    <FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
        <ShellContent ContentTemplate="{DataTemplate pages:AllVocabs}" Title="Alle Vokabeln" Icon="Book.png"/>
        <ShellContent ContentTemplate="{DataTemplate pages:deklkonj}" Title="Deklinationen" Icon="table.png"/>
        <ShellContent ContentTemplate="{DataTemplate pages:Konjugationen}" Title="Konjugationen" Icon="table.png"/>
        <ShellContent ContentTemplate="{DataTemplate pages:adjectives}" Title="Adjektive" Icon="table.png"/>
        <ShellContent ContentTemplate="{DataTemplate pages:profile}" Title="Profil" Icon="account.png"/>
    </FlyoutItem>
</Shell>

I have an App that's in development for quite a while now and I wanted to "port" it to iOS.

您要将您的应用移植到 Xamarin.Forms 还是 Xamarin.iOS

FinishedLaunching中的代码与这两种方式完全不同。

如果Xamarin.Forms

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App());

    return base.FinishedLaunching(app, options);
}

如果Xamarin.iOS

//AppDelegate (< iOS13)
[Export ("application:didFinishLaunchingWithOptions:")]
public bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{          
   Window = new UIWindow (UIScreen.MainScreen.Bounds);
   Window.RootViewController = new UIViewController();
   Window.MakeKeyAndVisible ();   // important 

   return true;
}
//SceneDelegate (>= iOS13)
[Export ("scene:willConnectToSession:options:")]
public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
    Window = new UIWindow(scene as UIWindowScene);
    Window.RootViewController = new UIViewController();
    Window.MakeKeyAndVisible ();   //important
}

使用 this 我发现 info.plist 文件中有几行导致了这个问题。您只需要从 info.plist 中删除这些行,它就可以正常工作。

 <key>UIApplicationSceneManifest</key>
 <dict>
     <key>UIApplicationSupportsMultipleScenes</key>
     <true/>
 </dict>