Hello guys , we are back once again with same previous topic i.e: Microsoft Dynamics Mobile Apps but with a new exciting and very much interesting feature that can be added with it i.e: offline capability. It sounds interesting. Yes it is. Until now, according to my knowledge which can be limited, all the mobile apps regarding Microsoft Dynamics are having online functionality. So, adding offline functionality will be a new journey for Microsoft Dynamics Mobile Apps.

So question arises how can we add offline functionality in mobile app? Answer is very simple. SQLITE DATABASE.

SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. For futher information, you can visit this link.

I am giving you just a short hand knowledge how to use it conceptually. As, Sqlite has very much space, so when you have internet connection, sync all the necessary information like orders, tables etc in your sqlite database for the use. Do whatever you want. Then when you have internet connection, do sync again.

If you are developing cross platform mobile application, then code for sqlite database path is different on platform level. So below is the code for both android and iOS platforms. Before it, you just have to include interface(I am naming it ILocalFileHelper).

Shared Level:

This is interface:

public interface ILocalFileHelper
{
SQLite.Net.SQLiteConnection GetConnection();
}

This is c# class for connectivity:

public class yourclass_name
{
private SQLite.Net.SQLiteConnection _sqlconnection;

public yourclass_name()
{
_sqlconnection = DependencyService.Get<ILocalFileHelper>().GetConnection();

}

In Android:

Just take a c# class(I am naming it LocalFileHelper) and add following code in it. It is the same class where you can add your CRUD functions and play around with them:

class LocalFileHelper : ILocalFileHelper
{
public SQLite.Net.SQLiteConnection GetConnection()
{
var filename = “your_database_name.db3”;
var documentspath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = Path.Combine(documentspath, filename);

var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
var connection = new SQLite.Net.SQLiteConnection(platform, path);
return connection;
}
}

Do not forget to add dependency before namespace:

[assembly: Dependency(typeof(LocalFileHelper))]

 

In iOS:

Just take a c# class(I am naming it LocalFileHelper) and add following code in it:

public class LocalFileHelper:ILocalFileHelper
{
public SQLite.Net.SQLiteConnection GetConnection()
{
var fileName = “your_database_name.db3”;
var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var libraryPath = Path.Combine(documentsPath, “..”, “Library”);
var path = Path.Combine(libraryPath, fileName);

var platform = new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS();
var connection = new SQLite.Net.SQLiteConnection(platform, path);

return connection;
}
}

Do not forget to add dependency before namespace:

[assembly: Dependency(typeof(LocalFileHelper))]

 

So, that’s the brief introduction how we can add offline functionality in our mobile apps and make it more faster and easier to use. Stay tuned for more exciting blogs on Microsoft Dynamics Mobile Apps. See you soon guys.

Leave a Reply

Recent Comments

    Archives

    Categories