[英]ios App breaks on Createtableasync sqlite code in xamarin.forms
我的 xamarin.forms 應用程序在遇到_connection.CreateTableAsync<Models.Location>()
行時中斷。 我嘗試安裝 SQLite-net-pcl nuget package 的早期版本,但它仍然無法正常工作。 如果我查看應用程序 Output window 會有這些錯誤 -
2021-02-03 14:32:20.172608-0500 Excercise.iOS[17306:776656] *** -[UIApplication_runWithMainScene:transitionContext:completion:] 中的斷言失敗,UIApplication.m:4191 2021-02-03 14:32 :20.198946-0500 Excercise.iOS[17306:776816] [未指定] 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]錯誤獲取 systemgroup.com.apple.configurationprofiles 的系統組容器:98 2021-02-03 14:32:20.199394-0500 Excercise.iOS [17306:776816] [MC] 無法獲取配置文件系統組容器路徑。 使用預期路徑覆蓋:/Users/xamarinforms/Library/Developer/CoreSimulator/Devices/CF07B70A-5AEC-4307-AB50-864317F14B69/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
我不明白這是否與 Sqlite 有關。 上述錯誤是否與捆綁唱歌有關? 我用於登錄 Visual Studio 的 Apple ID 和帳戶不同。
我的 Sqlite ios 實現
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);
}
}
這是應用程序中斷的行 -
public loadData(){
string city = "";
await _connection.CreateTableAsync<Models.Location>();}
Model 位置 -
[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);
}
主頁.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) { }
}
}
你的 appdelegate 中不應該有RootViewController
代碼:
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);
}
您可以將這兩行( App.ScreenHeight
和App.ScreenWidth
)移動到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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.