4

I am wondering if there is a way to store some data in a app.config like file. The data I would like to store would be : URL's with their keys.

I have tries looking up property lists but I have no idea how to acces these?

Edit 1: The main idea is to use the file in my PCL (Portable Class Library). For multi-platform use.

Thanks for the help!

Glenn Bettens
  • 65
  • 1
  • 8
  • 1
    Why not just store in a text file and read from that? Or a SQLite db. You might as well hard code them in your app since the whole reason for putting stuff in a .config file in the web is pretty much a moot point on mobile devices. – valdetero Jul 11 '14 at 15:29

3 Answers3

2

Case anyone stumbles on this about the best answer I've found so far is.

Xam.Plugins.Settings by James Montemagno via: nuget

"Settings Plugin for Xamarin and Windows provides a consistent, cross platform settings plugin for Windows Phone Silverlight 8/8.1, Windows Phone 8.1, Windows Store, Xamarin.iOS, and Xamarin.Android when using a PCL or any project and is Xamarin.Forms and MvvmCross compatible. This makes it easier to create cross-platform .NET apps and have cross platform settings. Manage and use all settings from one PCL and save natively on each platform. *This plugin stores settings natively on each platform and does NOT save them to Json. This allows you to use native functionality such as PreferenceActivity on Android."

David
  • 1,131
  • 9
  • 22
0

No, there is really no app.config. For iOS there are plist-Files, which are simple structered XML Key Value files (1). In Xamarin.iOS you can bundle them as ressource and read it like that:

public string ReadValueFromSettings(string key)
{
        _log.Info();

        string result = "ValueNotFound";

        if (_settings == null)
        {
            if(File.Exists("Settings.plist"))
            {
                var path = NSBundle.MainBundle.PathForResource("Settings", "plist");
                _settings = new NSDictionary(path);
            }
        }

        if(_settings != null)
        {
            var value = _settings.ValueForKey(new NSString(key));

            if(value != null)
                result = value.ToString();
        }

        return result;
}
Markus
  • 97
  • 1
  • 7
0

We published a nuget library that provides the ConfigurationManager feature to Xamarin, especially suitable for Xamarin.Forms : PCLAppConfig

this allows to add a unique config file from your PCL project, and be read from all your app projects:

ConfigurationManager.AppSettings["config.text"];

you can find the full step by step here : http://xamariners.com/2016/08/17/appsettings-reader-xamarin-forms/