A Xamarin Forms example using SQLite.NET-PCL with Async

UPDATE: I do not recommend this solution anymore. The SQLite library used is unmaintained, has locking issues, and does not work with Android 8 (however someone kindly sent through a PR to update Android support). I recommend this nuget package https://www.nuget.org/packages/sqlite-net-pcl/ moving forward.

It took me a while to gather information from various sources to get a working base of SQLite.NET in Xamarin Forms using all asynchronous operations, so I thought I'd whip up a small demo app showing all the plumbing in place, with basic data been added and retrieved from the database.

The solution can be found here: https://github.com/michaeldimoudis/xam-forms-sqlitenet-async

I had a lot of issues with how dates got stored in the database. Everything coming from and back to the server was in UTC, and the only way I could reliably get dates out of the SQLite database was by storing DateTime as ticks in SQLite. This is an optional parameter on SQLiteConnectionString in the iOS/Android concrete connection implementations. Also make sure you explicitly set DateTimeKind to UTC when inserting DateTime's in the SQLite database.

Another thing is, you need class level locking around your database calls, or else you risk dead locking the app. This is a must. AsyncSemaphore comes to the rescue here.

Also there was no way I could drop database tables asynchronously, it just simply didn't work. I had to always use non async connection for dropping tables.

You also might find SQLite-Net Extensions very useful, I did, and it reduced the amount of code I had to write greatly. You can find more information about it here https://bitbucket.org/twincoders/sqlite-net-extensions. I might blog about some tips and tricks of using this simple ORM at a later date.

Hope this helps getting you started :)

Taming the keyboard in native app development with Xamarin Forms

Wow, it’s been over 2 years since I last blogged. I haven’t done much exciting techy things in my spare time for a while, I did build a deck, maybe I’ll blog how to build a deck, but I want to start blogging more about native app development using Xamarin Forms.

I am loving Xamarin Forms. I have been playing with this technology for a bit under a year now, on and off. I started as a noob, and have now become fairly proficient in it. So I’m hoping to share some unique tips and tricks I’ve found along the way.

My first blog post is about the soft keyboard, and how to tame it! A huge benefit of native mobile app development versus web mobile app development, is that you can get access to the soft keyboard. So you can resize your view when the keyboard pops up or down, including detecting the height of any accessory views, or auto correction attached to the keyboard, etc. This allows you to build your view with elegance, user experience, and design in mind.

For instance, Facebook Messenger’s interface, where you get some added action buttons that are always anchored above the keyboard, no matter if the keyboard is up or down, with accessory views on or not, or with auto correction displayed or not. You can build those added actions as a Grid of Buttons, but this blog post isn’t about that, it’s about resizing the View.

Read More

Reliably and speedily send mass emails via Amazon SES in C#

​Amazon provides an awesome and awesomely cheap service to send emails out called Amazon Simple Email Service (Amazon SES).  However it comes with sending volume limits; a sending quota and maximum send rate. This blog post is specifically about the maximum send rate and how you can send emails at, or close to, that maximum send rate.

So HOW exactly could you achieve sending bulk emails, easily, effectively and reliably, especially since it takes 5-7 seconds to send a single email to Amazon SES? Read on to find how I did it.

Read More