Learn how to make fully functional connected apps without internet connection using Xamarin and Azure Mobile Apps Service. Slides from my talk at Xamarin Dev Days held at CET Trivandrum
We all have installed lots of app in your mobile device and with latest advancements in storage technology it’s only going to increase
Tell me how many apps you use on a daily basis, only a few right ? Mail, Whatsapp, Search, FB, Twitter
There are loads of app sitting in our phone which we haven’t bothered to take a second look at it after installation
And you get all the goodness shown in the previous slides across the WW
Extremely powerful
You can do almost anything your backend would ever need to do with Azure. Data storage, authentication/authorization, push notifications, custom APIs, blob storage, etc.
Flexible
Need something lightweight? Azure is there.
Need something robust and powerful? Azure is there.
C# clients
I’m a frontend developer, I care a lot about how easy this makes MY job (selfish)
Many C# clients are written by Java developers, etc.
Easy to use C# client
Abstracts away much of pain of using a RESTful API
C# Features
Async / Await / TPL
Uses C# idioms
Properties, Fluent API
Seems obvious, but not always true (first class citizen)
Helps devs to create apps that are functional even in the absence of network connection
In offline mode , users will be able to create and modify data which will be saved in a local data store
When the app is back online, it syncs the local data with the backend
It also include support for detecting conflicts in cases such when the same record is modified at both client and backend
And also conflicts can be handled at both the ends,
Sync Table
Sync table api should be used to support offline mode. Remember that you needs to initialize the local store first before any sync operations
Local Store
Is the data persistence layer in the client device.
SDK provides a default local store implementation. For Windows, xamarin and android it’s based on SQLite and for iOS its based on Core.Data
Sync Context
Is associated with mobile service client object such as IMobileServiceClient and tracks changes made in the sync tables. It maintains an operation queue which keeps an ordered list of all the crud operations
Initalize local store first,
creates a sql lite db using mobileservice
Create a table using Define table method, schema to be used is derived from ToDoItem table
IMobileServiceSyncTable is used instead of IMobileServiceTable
Uses a local database for all the crud operations and the sync context preserves the table relationships by tracking
Working
While using sync table, the client code controls the syncing of the data to the backend. The data will be sent only when push call is made, similarly the data will be pulled from the backend via an explicity call only. No auto sync in there
Push
Operation on the sync context which sends all the changes since the last push. Please note that all the changes are sent at once and there is no option to sync individual tables. The SDK makes some REST API calls to send the data to the mobile backend which in turn inserts it to the server store
Pull
Pull is done based on per-table basis and customized to pull only a subset of data, then the Azure SDK inserts the data into the local data store
Implicit Pushes
If a pull is executed against a table that has pending local updates, it will first execute a push on the sync context which helps to minimize the conflict between your local changes and the new data from the server
Incremental Pushes
First parameter for a pull operation is query-name, if nothing is specified then the SDK will perform a incremental sync. In this case whenever a pull operation returns a set of results the latest updatedAt timestamp from that resultset is stored in SDK local system tables, subsequent pull will return records only after that timestamp
Code is not ideal for production env, for real world scenarios you need to write code in a way such that the data is synced when the network state changes
SyncAsync is used to sync all your offline data with the backend
To insert data we use InsertAsync method to insert the data into the local store and then calls the push method to sync it up with the backend
Similary we will do that for update and delete operations
What if a GetAll should only return favorites for that user.
Backend deletes expired handles when PNS rejects them
Maintain mapping between logical users/groups and device handles
With Xamarin it just isn’t your front end in C# it is your full backend server as well. With Azure or even on Linux running Mono or the CoreCLR your app is fully C# end to end!
Get started today with free 30 day trial of Xamarin at xamarin.com