Additional Topics. API Bindings Bindings Binding Native API’s Create Binding Project Drop Jar or.a...

Preview:

Citation preview

Additional Topics

API Bindings

Bindings

• Binding Native API’s

• Create Binding Project• Drop Jar or .a• Done

You wish!

Painful

Bindings Android

• Generate C# stubs from Java Classes• Simple Jar’s work without issues

• XML transforms for differences in C# / Java:– Anonymous inner classes– Data Type Mapping– Enums

• Samples available• Did I say it’s painful already?

Bindings iOS

• Have to define all Classes / Methods manually• ObjectiveSharpie command line tool– Great help– Still a lot of manual work

• linkwith.cs file requires manual adaption– C Libraries– iOS Frameworks

• Errors appear when linking

Let’s have a look

Urban Airship binding (MyWorldVision)

Bindings Conclusion

• Many API’s are already available, maintained by main developer (Facebook, Microsoft etc.)

• Try to avoid bindings if other Components / Packages are available (-> e.g. Parse)

• Read error messages• Use Xamarin Forums, Stackoverflow• Be patient!

SQLite

Crossplattform DB

Data Model

public class TodoItem { public TodoItem () { }

[PrimaryKey, AutoIncrement] public int ID { get; set; } public string Name { get; set; } public string Notes { get; set; } public bool Done { get; set; } }

Get Connection (Dependency Service)

public interface ISQLite { SQLiteConnection GetConnection(); }

Android Implementation

public SQLite.SQLiteConnection GetConnection () { var sqliteFilename = "TodoSQLite.db3"; string documentsPath = System.Environment.GetFolderPath

(System.Environment.SpecialFolder.Personal); // Documents folder var path = Path.Combine(documentsPath, sqliteFilename); // Create the connection var conn = new SQLite.SQLiteConnection(path); // Return the database connection return conn; }}

Usage

Init:database = DependencyService.Get<ISQLite> ().GetConnection ();database.CreateTable<TodoItem>();

SQL Query:return database.Query<TodoItem> ("SELECT * FROM [TodoItem] WHERE [Done] = 0");

Usage

LINQ Expressions:TodoItem GetItem (int id){ return database.Table<TodoItem> ().FirstOrDefault (x => x.ID == id); }

return database.Delete<TodoItem> (id);

Let’s have a look

SQLite Demo App

JSON.Net

Jason!

Decisions, decisions

System.Json vs Json.Net-> Use Json.Net unless you have a good reason

-> Less restrictive

Basic example

var todoItem = new TodoItem {ID = 1,Name = "Name”

};

var json = JsonConvert.SerializeObject (todoItem);Debug.WriteLine ("JSON representation of todoItem: {0}", json);

var person2 = JsonConvert.DeserializeObject<TodoItem> (json);Debug.WriteLine ("{0} - {1}", person2.ID, person2.Name);

Linq example

string jsontext = @"{ Name: 'Bob', HairColor: 'Brown' }";var bob = JObject.Parse (jsontext);

Debug.WriteLine ("{0} with {1} hair", bob["Name"], bob["HairColor"]);

Let’s have a quick look

JSON Example

UI Tests

Testcloud

TestCloud

Physical devices mounted in Rack

UI Test

• For all native Apps• Physical devices mounted in Rack• Run locally in Simulator (iOS, Android)• Deploy to Cloud for mass testing• 60 Device Minutes included

• More is a bit expensive

UI Test – how it works

• iOS: e.NativeView.AccessibilityIdentifier = value;• Android: e.NativeView.ContentDescription = value;

[Test]public void WelcomeTextIsDisplayed () {

AppResult[] results = app.WaitForElement (c => c.Marked ("Welcome to Xamarin Forms!"));app.Screenshot ("Welcome screen.");

Assert.IsTrue (results.Any ());}

Tests

Let’s have a look (Local App)

Tests

Let’s have a look (testcloud.xamarin.com)

Insights

Analytics & Crash Reports made easy

Usage

• Import Package• Register API Key• Done

Hold your horses…

• Uncaught Exceptions get reported automatically

• Exception Reporting for caught exceptions:Insights.Report(ex);

• User Identification• Events• Timed Events

Recommended