简体   繁体   中英

Xamarin.Forms app shows blue screen on IOS then the app closes

So when testing my app on an android emulator i had no problems, but when i tested my app on iOS, i get the starting blue screen of Xamarin then the app closes and i am taken to all the apps page on the emulator ( but it acts like it's still running since you still see the red square on visual studio that shows when the app is running).

So i don't get any error message, so i am not sure how i can find the problem since i'm new in mobile dev.

Any idea ? Thanks a lot !

在此处输入图片说明

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
        }
    }
}

AppDelegate.cs for iOS

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);
            }
        }
    }

Main.cs for iOS

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

Debug output when the app is loading then the blue screen closes and you see the initial screen with all the apps

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);
            

        }


     }
}

I have checked the repo in local site, find that the problem is CalendarPage .And after check that, the problem comes from ViewModel .

The BindingContext of CalendarPage is:

public CalendarPage()
{
    InitializeComponent();

    BindingContext = new CalendarPageViewModel();
}

If comment BindingContext , iOS will show view. However , when click CalendarPage tab, the view will always hold on that moment.

在此处输入图片说明

Therefore, the problem should be the CalendarPageViewModel . After checking that, when new CalendarPageViewModel() , it will invoke a Task thread. However, ListViewCollection.ItemsSource re-call the Task thread. It will deadlock your UI thread.

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;
}

Last, I find a workaround can make the app works in iOS. I'm not sure whehter it will affect some functions in this project, because I'm not the designer of this app and not familiar with it.

Comment the Initialize method in the constructor method of CalendarPageViewModel as follow:

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);
    }));
}

It will show no problem in iOS:

在此处输入图片说明

=================================update=================================

If you not adding the title and icon source for tabbar item, iOS will not show them.

MainPage.xml modified as follow:

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

Not forgetting to add icon source in iOS Resources folder.

在此处输入图片说明

The effect:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM