SettingsPlugin

Read and Write Settings Plugin for Xamarin and Windows


Project maintained by jamesmontemagno Hosted on GitHub Pages — Theme by mattgraham

Getting Started

Setup

Where Do Settings Get Saved?

This library uses the native settings management, which means all settings are persisted across app updates, saved natively, and can be integrated into native settings.

What Kind of Data Can I Store?

Since data is stored natively on each platform only certain data types are supported:

Using Settings APIs

It is drop dead simple to gain access to the Settings APIs in any project. All you need to do is get a reference to the current instance of ISettings via CrossSettings.Current:

private static ISettings AppSettings =>
    CrossSettings.Current;

public static string UserName
{
  get => AppSettings.GetValueOrDefault(nameof(UserName), string.Empty); 
  set => AppSettings.AddOrUpdateValue(nameof(UserName), value); 
}

There may be instances where you install a plugin into a platform that it isn’t supported yet. This means you will have access to the interface, but no implementation exists. You can make a simple check before calling any API to see if it is supported on the platform where the code is running. This if nifty when unit testing:

private static ISettings AppSettings
{
    get 
    {
        if(CrossSettings.IsSupported)
            return CrossSettings.Current;
        
        return null; // or your custom implementation 
    }
}

<= Back to Table of Contents