[英]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>
我有一個應用程序正在開發很長一段時間,我想將它“移植”到 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
}
使用這個我發現 info.plist 文件中有幾行導致了這個問題。 您只需要從 info.plist 中刪除這些行,它就可以正常工作。
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
</dict>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.