Hi I'm doing an app that has a login, and it has the option to keep you login even if you turn off the app.
What is the problem? This is what I'm doing this in App.cs:
var statusLog = Application.Current.Properties["logStatus"].ToString();
if (statusLog == "F")
{
Application.Current.MainPage = new NavigationPage(new LoginPage());
}
else
{
var userStore = (Application.Current.Properties["user"].ToString());
Task.Run(() => lp.GetTokenLogin()).Wait();
MainPage = new NavigationPage(new ConfirmarViatura(userStore));
}
It works fine, but their is one situation that it do not work, that is if I run the app for the first time in the device, it gives me a exception that the local variable "logStatus" do not exists. I understand it do not exists, but how can i do this verification? I can't do this :
if (Application.Current.Properties["logStatus"].Equals(null))
{
Application.Current.Properties["logStatus"] = "F";
}
This do not work because the variable dosen't even exists. Any ideas?
You can check it this way:
if (Application.Current.Properties.ContainsKey("logStatus"))
{
var statusLog = Application.Current.Properties["logStatus"] as string;
// rest of your code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With