android studio中的共享首选项的xamarin(ios)中是否有一些模拟用于在启动之间保存数据?
或者最好的方法 - 写入文件并在需要时阅读?
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);
};
答案 0 :(得分:3)
在iOS中,您可以使用NSUserDefaults来存储配置和偏好数据
// Get Shared User Defaults
var plist = NSUserDefaults.StandardUserDefaults;
// Save value
plist.SetString(userName, "UserName");
// Sync changes to database
plist.Synchronize();
答案 1 :(得分:1)
看看NSUserDefaults。
将字符串写入:NSUserDefaults.StandardUserDefaults.SetString(value, key);
阅读以下字符串:NSUserDefaults.StandardUserDefaults.StringForKey(key);