[英]Xamarin.Forms app shows blue screen on IOS then the app closes
因此,當我在 android 模擬器上測試我的應用程序時,我沒有問題,但是當我在 iOS 上測試我的應用程序時,我得到了 Xamarin 的起始藍屏,然后應用程序關閉,我被帶到模擬器上的所有應用程序頁面(但它就像它仍在運行一樣,因為您仍然會在 Visual Studio 上看到顯示應用程序運行時間的紅色方塊)。
所以我沒有收到任何錯誤消息,所以我不確定如何找到問題,因為我是移動開發的新手。
任何的想法 ? 非常感謝 !
應用程序.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>
應用程序.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]
主頁.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>
主頁.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);
}
}
}
我檢查了本地站點的 repo,發現問題是CalendarPage 。檢查后,問題來自ViewModel 。
CalendarPage的BindingContext
是:
public CalendarPage()
{
InitializeComponent();
BindingContext = new CalendarPageViewModel();
}
如果注釋BindingContext
,iOS 將顯示視圖。 但是,當單擊CalendarPage選項卡時,視圖將始終保持在那一刻。
因此,問題應該是CalendarPageViewModel 。 檢查后,當new CalendarPageViewModel()
,它將調用一個 Task 線程。 但是, 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資源文件夾中添加圖標源。
效果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.