【问题标题】:Xamarin.Forms app shows blue screen on IOS then the app closesXamarin.Forms 应用程序在 IOS 上显示蓝屏,然后应用程序关闭
【发布时间】:2020-08-25 19:53:43
【问题描述】:

因此,在 android 模拟器上测试我的应用程序时,我没有任何问题,但是当我在 iOS 上测试我的应用程序时,我得到 Xamarin 的启动蓝屏,然后应用程序关闭,我被带到模拟器上的所有应用程序页面(但它的行为就像它仍在运行,因为您仍然在 Visual Studio 上看到显示应用程序运行时间的红色方块)。

所以我没有收到任何错误消息,所以我不确定如何找到问题,因为我是移动开发新手。

有什么想法吗?非常感谢!

App.xaml

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="Calculette.App">
    <Application.Resources>

    </Application.Resources>
</Application>

App.xaml.cs

using Calculette.Database;
using System;
using System.IO;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

//[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Calculette
{
    public partial class App : Application
    {
        
        static CalculetteDatabase database;
        public static CalculetteDatabase Database
        {
            get
            {
                if (database == null)
                {
                    
                    database = new CalculetteDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Calculette.db3"));
        
                }
                return database;
            }
        }

        public App()
        {
            InitializeComponent();
            //MainPage = new MainPage();
            // Pour pouvoir faire apparaitre la toolbaritems
            MainPage = new NavigationPage(new MainPage());
            ((NavigationPage)MainPage).BarBackgroundColor = Color.FromHex("#008A00");
            ((NavigationPage)MainPage).BarTextColor = Color.FromHex("#FFFFFF");
            

        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

适用于 iOS 的 AppDelegate.cs

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

using Foundation;
using UIKit;

namespace Calculette.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)
            {
    
                Xamarin.Forms.Forms.SetFlags(new string[] { "Expander_Experimental", "SwipeView_Experimental" });
                global::Xamarin.Forms.Forms.Init();
                LoadApplication(new App());
    
                return base.FinishedLaunching(app, options);
            }
        }
    }

iOS 的 Main.cs

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

using Foundation;
using UIKit;

    namespace Calculette.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");
            }
        }
    }

加载应用时的调试输出,然后蓝屏关闭,您会看到所有应用的初始屏幕

Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/Xamarin.iOS.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/Mono.Security.dll [External]
Resolved pending breakpoint for 'UIKit.UIApplication.Main(System.String[], System.IntPtr, System.IntPtr)' to /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:85 [0x00000].
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/Calculette.iOS.exe
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/Xamarin.Forms.Platform.iOS.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/Xamarin.Forms.Core.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/netstandard.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Core.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Xml.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Numerics.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Data.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Transactions.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Data.DataSetExtensions.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Drawing.Common.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.IO.Compression.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.IO.Compression.FileSystem.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.ComponentModel.Composition.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Net.Http.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Runtime.Serialization.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.ServiceModel.Internals.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Web.Services.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Xml.Linq.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/Xamarin.Forms.Platform.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/Calculette.dll
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/Xamarin.Forms.Xaml.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/XamForms.Controls.Calendar.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Runtime.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Resources.ResourceManager.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Collections.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.ObjectModel.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Threading.Tasks.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Globalization.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Threading.dll [External]
Loaded assembly: /Users/user179537/Library/Developer/CoreSimulator/Devices/CBBD6116-A257-42AB-B54A-9C00DF68934D/data/Containers/Bundle/Application/31B4CC71-FFB9-4A92-946F-B35391E22175/Calculette.iOS.app/System.Runtime.Extensions.dll [External]

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Calculette"
            xmlns:pv="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
            xmlns:views1="clr-namespace:Calculette.Views"
            xmlns:converters="clr-namespace:Calculette.Converters"
            x:Class="Calculette.MainPage"
            BarBackgroundColor = "White"
            BarTextColor="#008A00">


    <TabbedPage.ToolbarItems>
        <ToolbarItem Icon="logocalculette.png"></ToolbarItem>

        <ToolbarItem></ToolbarItem>
        <ToolbarItem></ToolbarItem>
        <ToolbarItem Text="Calculette de bruit"/>

        <ToolbarItem Text=""></ToolbarItem>
        <ToolbarItem Text="À propos" Order="Secondary"></ToolbarItem>
        <ToolbarItem Text="Références" Order="Secondary"></ToolbarItem>
        <ToolbarItem Text="Mentions légales" Order="Secondary"></ToolbarItem>
        <ToolbarItem Text="Aide" Order="Secondary"></ToolbarItem>
        <ToolbarItem Text="Options" Order="Secondary"></ToolbarItem>
    </TabbedPage.ToolbarItems>


    <views1:TasksGroupPage></views1:TasksGroupPage>
    <local:CalendarPage></local:CalendarPage>




</TabbedPage>

MainPage.xaml.cs

using Calculette.ViewModels;
using Calculette.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.PancakeView;
using Calculette.Views;

namespace Calculette
{
    public partial class MainPage : TabbedPage
    {

        public MainPage()
        {

            InitializeComponent();
            Xamarin.Forms.PlatformConfiguration.AndroidSpecific.TabbedPage.SetIsSwipePagingEnabled(this, false);
            

        }


     }
}

【问题讨论】:

  • 应用程序输出窗口显示什么?
  • @Jason 您需要哪个窗口,对于输出,我可以在构建、构建顺序、调试、包管理器、Xamarin、Xamarin 诊断之间进行选择。还有一种行为,一旦应用程序安装在模拟器上,当我再次运行项目时,它永远不会立即启动应用程序,我需要点击应用程序图标才能启动
  • 我添加了调试输出,它似乎卡在那里(至少 10 分钟,没有任何反应)
  • @codetime 你好,当应用关闭时,你能分享一下VS的OutPut的日志吗?另外,如果能分享一些Fomrs的代码就更好了。
  • @JuniorJiang-MSFT 您好,抱歉,我不确定 Fomrs 的代码是什么,它在哪里?你想要哪个 Vs 输出,我从我的第二条评论中得到了选项,并且已经在帖子中出现了首次输出。谢谢!

标签: ios xamarin xamarin.forms xamarin.ios


【解决方案1】:

我检查了本地站点的repo,发现问题是CalendarPage。检查后,问题来自ViewModel

CalendarPageBindingContext 是:

public CalendarPage()
{
    InitializeComponent();

    BindingContext = new CalendarPageViewModel();
}

如果评论BindingContext,iOS 将显示视图。 然而,当点击CalendarPage标签时,视图会一直停留在那个时刻。

因此,问题应该是CalendarPageViewModel。检查后,当new CalendarPageViewModel() 时,它将调用一个任务线程。但是,ListViewCollection.ItemsSource 重新调用了 Task 线程。它会使你的 UI 线程死锁。

protected override async void OnAppearing()
{

    base.OnAppearing();
    var vm = this.BindingContext as CalendarPageViewModel;
    Calendar.SelectedDates.Clear();
    vm.Date = null;
    vm.ExpanderBool = false;
    vm.PancakeViewBool = false;
       
    await vm.GetTasks();
    await vm.Initialize();
    ListViewCollection.ItemsSource = vm.Tasks;
}

最后,我发现一个解决方法可以让应用在 iOS 中运行。我不确定它是否会影响这个项目中的一些功能,因为我不是这个应用程序的设计者,也不熟悉它。

CalendarPageViewModel的构造方法中注释Initialize方法如下:

public CalendarPageViewModel()
{
    //Initialize().GetAwaiter().GetResult();

    DeleteClickedCommand = new Command(new Action<object>(async (obj) =>
    {

        await DeleteClicked(obj);
    }));

    ResultPageClickedCommand = new Command(new Action<object>(async (obj) =>
    {

        await ResultPageClicked(obj);
    }));

    AddTaskButtonClickedCommand = new Command(new Action<object>(async (obj) =>
    {

        await AddTaskButtonClicked(obj);
    }));
}

在 iOS 中不会显示问题:

===================================更新============ =====================

如果你不添加标签栏项目的标题和图标源,iOS 将不会显示它们。

MainPage.xml修改如下:

...
<views1:TasksGroupPage Title="TasksGroup" IconImageSource="iconcalendrier.png"></views1:TasksGroupPage>
<local:CalendarPage Title="Calendar" IconImageSource="icontache.png"></local:CalendarPage>
...

不要忘记在 iOS Resources 文件夹中添加图标源。

效果:

【讨论】:

  • 您好,感谢您的帮助,非常感谢。我认为他不喜欢 .GetAwaiter().GetResult();所以我重新实现,所以它不使用它,它似乎工作得很好,再次感谢!
  • 讨厌顶部的工具栏项目与带有汉堡菜单的 android 不一样哈哈
  • @codetime 原因是iOS解决方案没有在Resources文件夹中添加图标源。我会更新答案。此外,如果不添加,选项卡标题现在也会显示。
  • 是的,我忘了添加这些图标,但我在谈论 A 提案、参考等。在 Android 的顶部,它是一个名为toolbaritems 的汉堡菜单,而在 iOS 上,它都是扩展且丑陋的哈哈,但是我听说 iOS 不喜欢汉堡菜单?
  • @codetime 是的,iOS 没有与 Android 相同的工具栏。如果需要,它应该在 iOS 中自定义页面。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-06
  • 2011-12-20
  • 1970-01-01
相关资源
最近更新 更多