Cross Platform Settings for Everyone!
If you haven’t figure it out by now, I simply love portable class libraries. I have been blogging about them, talking about them on Channel 9, and I even did a 18 city roadshow discussing PCLs and Azure Mobile Services.
On my GitHub I have started to build out a lot of applications, sometimes using MvvmCross and sometimes not. One of my most starred repos is my MvvmCross plugin for saving settings on Android, iOS, WP, and Win 8. My idea originally was simple: Use the native settings management system across all platforms. This means SharedPreferences, NSUserDefaults, IsolatedStorageSettings, and ApplicationDataContainer. I didn’t want to do anything too crazy to re-invent the wheel, so this means you can only store data values that the platform allows such as:
- Boolean
- Int64
- String
- Single
- DateTime
Doing anything more then this to me means you should use some sort of blob storage such as Akavache. Since my library is very simple this means you can still use a PreferenceActivity on Android to get a nice native settings screen (this was my main motivation really). So it is great that I have MvvmCross support, but what about standard Xamarin projects?
Today, I am pleased to introduce a brand new GitHub repo called “Xam.PCL.Plugins”. This is a repo that is open source and will house all of my PCL NuGet Plugins for cross platform development. To start things off I am introducin my very first plugin, which as you might have guessed is cross platform settings! It is already available on NuGet for your app consumption :)
All you need to do is install the NuGet into both your PCL and client projects and you will be on your way! If you are interested in creating more plugins with me or converting MvvmCross plugins over simply fork my repo and send a pull request. You can use my settings project as an example of how to structure your project to work properly with PCLs. Additionally, PCLStorage is a great repo to also look at for starting development for a more advanced PCL.