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)
For slightly more secure storage choose either
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.
If you need a more traditional relational database to store information the best option is SQLite. It is very popular and heavily used.
However if you want to use it in Xamarin Forms you will need to use a bit of dependency injection.
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.
Wouldn’t it be great. Apologies to disappoint here but it is available for UWP but there has been no port for MonoAndroid or MonoTouch and I can not find anything on any roadmap that they will even be trying. I was really hoping as I have a lot of past EF experience, even EF7 with ASP.NET5 and I was really hoping to see it in Xamarin. Maybe one day we will but I wouldn’t bank any upcoming or current project on it.
The only option of anything above SQLite is SQLite Extensions.