简体   繁体   中英

ios App breaks on Createtableasync sqlite code in xamarin.forms

My xamarin.forms app is breaking when it hits the _connection.CreateTableAsync<Models.Location>() line. I tried installing the earlier version of SQLite-net-pcl nuget package but it is still breaking. If I look in the Application Output window there are these errors -

2021-02-03 14:32:20.172608-0500 Excercise.iOS[17306:776656] *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], UIApplication.m:4191 2021-02-03 14:32:20.198946-0500 Excercise.iOS[17306:776816] [unspecified] container_system_group_path_for_identifier: error = ((container_error_t)98) NOT_CODESIGNED 2021-02-03 14:32:20.199159-0500 Excercise.iOS[17306:776816] [MC] Error getting system group container for systemgroup.com.apple.configurationprofiles: 98 2021-02-03 14:32:20.199394-0500 Excercise.iOS[17306:776816] [MC] Failed to get profile system group container path. Overriding with expected path: /Users/xamarinforms/Library/Developer/CoreSimulator/Devices/CF07B70A-5AEC-4307-AB50-864317F14B69/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

I can't understand if this has something to do with Sqlite. Are the above errors related to bundle singing by any chance? My apple id and account that I used to signin to Visual studio are different.

My Sqlite ios implementation

public class SQLiteDb : ISQLiteDb
    {
        public SQLiteAsyncConnection GetConnection()
        {
            var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
            var path = Path.Combine(documentsPath, "MySQLite21.db3");

            return new SQLiteAsyncConnection(path);
        }
    } 

This is the line where the app breaks -

public loadData(){
                string city = "";
                await _connection.CreateTableAsync<Models.Location>();}

Model Location -

 [Table("Location")]
    public class Location 
    {
        [SQLite.PrimaryKey,SQLite.AutoIncrement]
        public int Id { get; set; }

        [MaxLength(255)]
        public string City {
            get;set;
        }

        public string LocationKey
        {
            get;set;
        }

        public string State { get; set; }

        public string Country { get; set; }

        public string StateID { get; set; }

        public bool LastSelected { get; set; }
        
        public string TimeZoneName { get; set; }

        public string TimeZoneCode { get; set; }
    }

AppDelegate.cs

UIWindow uIWindow;
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            try
            {
                global::Xamarin.Forms.Forms.Init();

                App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height;
                App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width;
               
                LoadApplication(new App());
            }
            catch(Exception ex)
            {
                string str = ex.Message;
            }
            uIWindow = new UIWindow(UIScreen.MainScreen.Bounds);
            uIWindow.RootViewController = new UIViewController();
            uIWindow.MakeKeyAndVisible();

            return base.FinishedLaunching(app, options);
        }

HomePage.cs -

 public HomePage()
        {
            InitializeComponent();
            _connection = DependencyService.Get<ISQLiteDb>().GetConnection();
            loadData("");
            downloader.OnFileDownloaded += OnFileDownloaded;
        }

App.xaml.cs -

public App()
        {
            Device.SetFlags(new string[] { "RadioButton_Experimental" });
            InitializeComponent();
            LoadStyles();
            try
            {
                MainPage = new MainPage();
            }
            catch(Exception ex)
            {
                string str = ex.Message;
            }
        }

  void LoadStyles()
        {
            if (IsASmallDevice())
            {
                dictionary.MergedDictionaries.Add(SmallDeviceStyles.SharedInstance);
            }
            else
            {
                dictionary.MergedDictionaries.Add(GeneralDeviceStyles.SharedInstance);
            }
        }

        public static bool IsASmallDevice()
        {
            // Get Metrics
            var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;

            // Width (in pixels)
            var width = mainDisplayInfo.Width;

            // Height (in pixels)
            var height = mainDisplayInfo.Height;
            return (width <= smallWidthResolution && height <= smallHeightResolution);
        }

MainPage.cs -

 public partial class MainPage : MasterDetailPage
    {
        public MainPage()
        {
            InitializeComponent();
            try
            {
                MasterBehavior = MasterBehavior.Popover;
                //  Detail = new HomePage();
                this.Title = App.AppTitle;
                App.stopWatch.Start();
            }
            catch(Exception ex) { }
        }
}

You should not have the RootViewController code in your appdelegate:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        try
        {
            global::Xamarin.Forms.Forms.Init();               
            LoadApplication(new App());
        }
        catch(Exception ex)
        {
            string str = ex.Message;
        }

        return base.FinishedLaunching(app, options);
    }

And you can move those two lines( App.ScreenHeight and App.ScreenWidth ) to HomePage :

 public HomePage()
        {
            InitializeComponent();

            App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height;
            App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width;
 
            _connection = DependencyService.Get<ISQLiteDb>().GetConnection();
            loadData("");
            downloader.OnFileDownloaded += OnFileDownloaded;
        }

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