Local Storage (Day 10)

Local storage can be needed for a number of things, user preferences, security tokens or caching downloaded data. What I will go through in this post is where and some ways to retain information locally on the device.

The common ones are:

  • Keychain / KeyStore
  • NSUserDefaults / SharedPreferences
  • Internal (Application) Storage
  • External Storage
  • SQLite (though really just a file in storage)

StorageOptions

For slightly more secure storage choose either

  • KeyStore
  • KeyChain
  • IsolatedStorage
  • ApplicationDataContainer

Your next best option is to always choose something in Internal Storage. Internal Storage means only the mobile app can access this data and not any other application. External Storage is available to any app on the phone and is not secure.

For secure storage have a look at Secure Storage on XLabs.

For internal settings storage have a look at the Settings Plugin for Xamarin. Its great for storing persistent non sensitive data.

SQLite

If you need a more traditional relational database to store information the best option is SQLite. It is very popular and heavily used.

Download SQLite.Net.Async PCL and it will download the other dependencies for you. This gives you SQLite capabilities and you can see some examples on their GitHub page.

However if you want to use it in Xamarin Forms you will need to use a bit of dependency injection.

Windows Phone

iOS

Android

SQLCipher

If you need your local SQLite database to be secured you can use SQLCipher. Its free if you have a Xamarin Enterprise License otherwise its a paid product. It encrypts the database locally so that even if the phone is stolen the database will still be secure.

Entity Framework

Entity Framework is available for Xamarin, and can be used in iOS, Android and UWP. Have a look at Entity Framework Core with Xamarin.Forms.

Couchbase (NoSQL)

If you are looking for a NoSQL database, Couchbase Lite is a popular option. You can download the NuGet package and read the Getting Started guide to get up and running really fast.


5 Common Pitfalls In Enterprise Mobile Development

Based on my experience, of over 9,000hrs of Xamarin.Forms development, check out some of my hard learnt lessons, in enterprise Xamarin.Forms development.

<< Security And Authentication (Day 9) || Styling UI/UX (Day 11) >>

14 Days To Building An Enterprise Quality Xamarin Forms App


XAMARIN.FORMS MONTHLY NEWSLETTER

JOIN 1,000+ SUBSCRIBERS

  1. Don't miss out on updates
  2. The latest info from this site, Xamarin and the community
  3. Unsubscribe at any time*

* We use MailChimp, with double opt-in, and instant unsubscribe

Microsoft MVP | Xamarin MVP | Xamarin Certified Developer | Exrin MVVM Framework | Xamarin Forms Developer | Melbourne, Australia

Related Posts

2 Comments

Leave A Comment?