Xamarin with SQLite Telerik School Academy Xamarin apps for iOS, Android & WinPhone.

Post on 13-Dec-2015

238 views 1 download

Tags:

Transcript of Xamarin with SQLite Telerik School Academy Xamarin apps for iOS, Android & WinPhone.

Working with local data

Xamarin with SQLite

http://schoolacademy.telerik.com

Telerik School Academyhttp://schoolacademy.telerik.com

Xamarin apps for iOS, Android & WinPhone

2

Table of Contents

1. Architecture

2. Install SQLite.NET – for PCL Project

3. Implementation Shared code

Android

iOS

Windows Phone

Architecture

3

4

Architecture

Install SQLite.NET – PCL Project

Implementation Shared code

Android

iOS

Windows Phone

SQLite for PCL Project PCL – Portable Class Library Install SQLite.Net PCL from NuGet

5

6

Architecture Install SQLite.NET – PCL Project Implementation

Shared code Android

iOS

Windows Phone

Shared Code Initial database setup requires platform-

specific work Use Interfaces to abstract any platform-

specific functionality

Use the DependencyService to obtain an implementation

public interface ISQLite { SQLiteConnection GetConnection(); }

7

public ItemDatabase() { SQLiteConnection database = DependencyService

.Get<ISQLite>().GetConnection(); InitializeDatabase(database);}

SQLite.NET syntax Create Table

Read item/s from database

Create/Add item to the database

Delete item from the database

Updata item in the database

database.CreateTable<T>();

8

database.Table<T>();

database.Insert(item);

database.Delete<T>(item);

database.Update(item);

9

Architecture Install SQLite.NET – PCL Project Implementation

Shared code

Android iOS

Windows Phone

10

Android Add SQLite.PCL – XamarinAndroid

Platform from NuGet

Database locationvar sqliteFilename = "SQLite.db3";string docPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);

var path = Path.Combine(docPath, sqliteFilename);

11

Android Implement ISQLite Add assembly Dependency[assembly: Dependency (typeof (SQLite_Android))]public class SQLite_Android : ISQLite { public SQLiteConnection GetConnection () { var path = ...; var connection = new SQLiteConnection( new SQLitePlatformAndroid(), path);

return connection; }}

12

Architecture Install SQLite.NET – PCL Project Implementation

Shared code

Android

iOS Windows Phone

13

iOS Add SQLite.PCL – XamarinIOS

Platform from NuGet

Database locationvar sqliteFilename = "SQLite.db3";string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);string libraryPath = Path.Combine (documentsPath, "..", "Library");

var path = Path.Combine(libraryPath, sqliteFilename);

14

iOS Implement ISQLite Add assembly Dependency[assembly: Dependency (typeof (SQLite_iOS))]public class SQLite_iOS : ISQLite { public SQLiteConnection GetConnection () { var path = ...; var connection = new SQLiteConnection( new SQLitePlatformIOS(), path);

return connection; }}

15

Architecture Install SQLite.NET – PCL Project Implementation

Shared code

Android

iOS

Windows Phone

16

Implementation – WinPhone

Windows Phone does not include the SQLite database engine Download and Install

Precompiled Binaries for Windows Phone 8

Add References

Windows Phone SDK 8.0 > Extentions > SQLite

WinPhone Add SQLite.PCL – WindowsPhone8

Platform from NuGet

Implement ISQLitevar sqliteFilename = "SQLite.db3";

string path = Path.Combine( ApplicationData.Current.LocalFolder.Path, sqliteFilename);

17

18

WinPhone Implement ISQLite Add assembly Dependency[assembly: Dependency (typeof (SQLite_WinPhone))]public class SQLite_WinPhone : ISQLite { public SQLiteConnection GetConnection () { var path = ...; var connection = new SQLiteConnection( new SQLitePlatformWP8(), path);

return connection; }}

Xamarin with SQLiteLive Demo

19

20

Summary Architecture Install SQLite.NET

For PCL Project

Implementation Shared code

Android

iOS

Windows Phone

форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно

програмиране за деца – безплатни курсове и уроцибезплатен SEO курс - оптимизация за търсачки

уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop

уроци по програмиране и уеб дизайн за ученициASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC

безплатен курс "Разработка на софтуер в cloud среда"

BG Coder - онлайн състезателна система - online judge

курсове и уроци по програмиране, книги – безплатно от Наков

безплатен курс "Качествен програмен код"

алго академия – състезателно програмиране, състезания

ASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NETкурсове и уроци по програмиране – Телерик академия

курс мобилни приложения с iPhone, Android, WP7, PhoneGap

free C# book, безплатна книга C#, книга Java, книга C#Дончо Минков - сайт за програмиранеНиколай Костов - блог за програмиранеC# курс, програмиране, безплатно

?

? ? ??

?? ?

?

?

?

??

?

?

? ?

Questions?

?

Working with local data

http://academy.telerik.com

Free Trainings @ Telerik Academy

C# Programming @ Telerik Academy csharpfundamentals.telerik.com

Telerik Software Academy academy.telerik.com

Telerik Academy @ Facebook facebook.com/TelerikAcademy

Telerik Software Academy Forums forums.academy.telerik.com