Reputation: 4433
Is there a some analog in xamarin (ios) of shared preferences in android studio to save data between launches?
Or the best way to do this - write in file and read when its needed?
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
var webClient = new WebClient();
var url = new Uri("some_url");
webClient.DownloadStringCompleted += (s, e) =>
{
var text = e.Result;
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string localFilename = "downloaded.txt";
string localPath = Path.Combine(documentsPath, localFilename);
File.WriteAllText(localPath, text);
long miliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
NSUserDefaults.StandartUserDefaults.setBool(true, "Boolean"); //the name 'NSUserDefaults' does not exist in the current context - why?
webClient.DownloadStringAsync(url);
};
Upvotes: 0
Views: 153
Reputation: 2881
Take a look at NSUserDefaults.
Write a string to: NSUserDefaults.StandardUserDefaults.SetString(value, key);
Read a string from: NSUserDefaults.StandardUserDefaults.StringForKey(key);
Upvotes: 1
Reputation: 89082
in iOS, you can use NSUserDefaults to store configuration and preferences data
// Get Shared User Defaults
var plist = NSUserDefaults.StandardUserDefaults;
// Save value
plist.SetString(userName, "UserName");
// Sync changes to database
plist.Synchronize();
Upvotes: 3