Thomas Swaney
asked on
Help with example code for Xamarin.Forms
I am new to Xamarin, C# and SQLite. I found a article https://msdn.microsoft.com/en-us/magazine/mt736454.aspx.
Basically I can get the Android code to work properly but I can't get the IOS code to work.
The emulator starts on the mac but then I get the error that you see in the attached file. I understand that it is due to something not getting passed but don't understand what that is.
Any help would be greatly appreciated so that I can move forward with this project.
Thanks in advance
SQLite_IOS_Error.png
Basically I can get the Android code to work properly but I can't get the IOS code to work.
The emulator starts on the mac but then I get the error that you see in the attached file. I understand that it is due to something not getting passed but don't understand what that is.
Any help would be greatly appreciated so that I can move forward with this project.
Thanks in advance
SQLite_IOS_Error.png
ASKER
I changed the code in the CustomersDataAccess class to
It still doesn't work with IOS but works with Android.
I feel that it has something to do with either the DatabaseConnection_Android class or the DatabaseConnection_IOS class.
DatabaseConnection_Android .cs
DatabaseConnection_IOS
public CustomersDataAccess()
{
SQLiteConnection database = DependencyService.Get<IDatabaseConnection>().DbConnection();
// database =
// DependencyService.Get<IDatabaseConnection>().
// DbConnection();
database.CreateTable<Customer>();
this.Customers =
new ObservableCollection<Customer>(database.Table<Customer>());
// If the table is empy, initialize the collection
if (!database.Table<Customer>().Any())
{
AddNewCustomer();
}
}
It still doesn't work with IOS but works with Android.
I feel that it has something to do with either the DatabaseConnection_Android
DatabaseConnection_Android
using SQLite;
using LocalDataAccess.Droid;
using System.IO;
[assembly: Xamarin.Forms.Dependency(typeof(DatabaseConnection_Android))]
namespace LocalDataAccess.Droid
{
public class DatabaseConnection_Android : IDatabaseConnection
{
public SQLiteConnection DbConnection()
{
var dbName = "CustomersDB.db3";
var path = Path.Combine(System.Environment.
GetFolderPath(System.Environment.
SpecialFolder.Personal), dbName);
return new SQLiteConnection(path);
}
}
}
DatabaseConnection_IOS
using LocalDataAccess.iOS;
using SQLite;
using System;
using System.IO;
[assembly: Xamarin.Forms.Dependency(typeof(DatabaseConnection_iOS))]
namespace LocalDataAccess.iOS
{
public class DatabaseConnection_iOS
{
public SQLiteConnection DBConnection()
{
var dbName = "CustomersDb.db3";
string personalFolder =
System.Environment.
GetFolderPath(Environment.SpecialFolder.Personal);
string libraryFolder =
Path.Combine(personalFolder, "..", "Library");
var path = Path.Combine(libraryFolder, dbName);
return new SQLiteConnection(path);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found the solution and the solution giving was not the fix for the problem.
Open in new window
or maybeOpen in new window