How to implement a Settings UI in Xamarin.Forms?

5.4k Views Asked by At

It is considered best practice in iOS to implement a Settings Bundle so the user can access your app settings from the iOS Settings app as well as from within your app. However, this is a unique concept to iOS. Given that, if you want to implement a settings UI, how should you do it in Xamarin.Forms so that you get the Settings Bundle for iOS and still have a Settings View of some sort that is available on the other platforms?

3

There are 3 best solutions below

1
On

Since the Settings Bundle is a very iOS specific feature, implementing that in the iOS project is the only way.

Then I would create an ISettings interface to get back specific settings. In iOS create a class that gets / sets the settings in this bundle and use dependency injection.

Then implement something else for Android and WinPhone. You should be able to create a common shared page but the Set and Get methods will switch relevant to each platform.

0
On

Forms provides several ways to customize behavior per-platform. You can use Device.OS or Device.OnPlatform() to create behavior (ie, a Settings option on your main menu) that exists on Windows and Android, but does not on iOS (instead letting the user use the Settings bundle).

0
On

Use this: https://github.com/jamesmontemagno/SettingsPlugin

UPDATE: Use this: https://learn.microsoft.com/en-us/xamarin/essentials/preferences (Xamarin.Essentials supplants much of the great x-plat stuff that James Montemagno originally put together)

It provides a cross-platform API for dealing with settings. It will store your settings in a plist on iOS.

As far as building your settings UI by simply referencing the plist (like iOS does natively), that's not really a thing in Forms. In Forms, you would implement your own custom settings Page using the Forms APIs. Forms has a TableView UI element on which you can set the Intent property. Intent can be set to a value of Data, Form, Menu, or Settings. You can use the Settings value to indicate that you want the TableView to resemble an iOS settings screen. Then simply bind each of your TableView items to your settings class.