Build a Cross-platform App with Kii and Xamarin in Minutes

kii_plus_xamarin

Struggling with the peculiarities and gotchas of each mobile platform? Want to develop apps that are multiplatform while still being native (not javascript/html)?

Here’s a great opportunity to save countless hours on you next multiplatform app by using one code base and a snap-in app backend-as-a-service.

What do I need to get started?

  • Xamarin Studio
  • Kii C# SDK
  • Some .NET coding skills (a little bit of C#)

Xamarin Studio is an IDE form the creators of Mono (an open source .NET stack). Being .NET experts they came up with the idea that they could provide a .NET based IDE and allow compilation and deployment for multiple platforms including Android, iOS and Windows Phone. The system automatically installs a run-time on the target device that allows it to run .NET assemblies. This way the platform specific code is minimized and there’s a lot of common code that you can share between platforms (and code/maintain on a single place).

What do I have to do?

Let’s take a look at a popular demo from the Xamarin team: Tasky. Tasky is a bare bones task manager (laundry, errands, etc) that serves as an excellent example of how to create a multiplatform app. It consists on a projects with all the shared code (Tasky.Core) and then it provies the platform specific code in separate projects (Tasky.Droid, Tasky.iOS, etc). Moreover the demo shows a good division of application layers (business, data, ui) which makes it very easy to replace the data management layer with our Kii data management service (which is exactly what we’re going to do here).

First of all we need to reference the Kii C# SDK assemblies from the project (you can download them from here, choose the Unity SDK). Now download and install Xamarin Studio, open the project with it, locate the Tasky.Core project, locate the References folder inside the project file hierarchy, do a right click and select Edit References. Here you just have to locate our assemblies downloaded above: JsonOrg.dll and KiiCloudStorageSDK.dll (do the same for each platform specific project, eg Tasky.Droid).

Then you have to replace data management calls in your Data layer with Kii Cloud API calls. A good example is the modified Task project. In it you’ll see that the main business class is, not surprisingly, called Task and that a TaskManager handles all the task operations via a TaskRepository/TaskDatabase. The TaskDatabase builds on SQLite.Net and represents a specific database, in this case, the Task DB. It contains methods for retrieval and saving as well as database creation, all based on the underlying ORM. But of course, the database is stored in a local file so all your tasks are on a single device. The minute you move to a different device you have to start all over again.

What are the advantages?

With a Kii Cloud based data provider your data is on the cloud and can be shared across devices and platforms (as long as you authenticate to the service with the same user). So by using one IDE and one back-end SDK to deploy to multiple platforms you provide an integrated app experience while saving precious development time.

Take a look at the code that shows how to replace the old TaskRepository with a cloud based repository (using Kii Cloud). For the sake of simplicity we’re hard-coding a username/password here (but you’ll have to provide a screen to allow user sign-up/login so the same user manages the same tasks across any device and platform). As you can see it’s all based on cloud calls that do not rely on local storage!

How do I get the code?

The app looks like this running from the same Kii code base on iOS and Android:

Tasky_iOS_Android

You can download the project from this git repository.

Enjoy!

- Share -

German Viscuso

More posts from

  • Kii IoT platform enables customers to create smart, connected solutions and services
  • Long track record of supporting customers like Docomo, Toshiba, Kyocera and many others
  • Strong ecosystem partners across the globe, consisting of carriers, device/sensor manufacturers, system integrators, network/infrastructure providers, chip vendors and solution developers
  • HQ in Tokyo, US HQ in Silicon Valley & offices in China, Taiwan, Hong Kong and Europe (UK, Spain, Germany)
  • www.kii.com