简体   繁体   中英

how can i use httpclient too create a function that will keep the user login alive even after the app shut done?

I'm having a problem with this, because I want to keep the app logged in if the user just slide the switch that I have in the Login page. My question is how can I do this with the HttpClient in order to continue using the same session.

Thanks to anyone o could give me some info on this.

I'm assuming that what you want is to save the token that your API will retrieve if you make a successful login.

For this, you want to save, into storage, the token and you can use the Xamarin.Essentials package , most specifically the Secure Storage Plugin

try
{
  await SecureStorage.SetAsync("oauth_token", "secret-oauth-token-value");
}
catch (Exception ex)
{
  // Possible that device doesn't support secure storage on device.
}

And to retrieve it:

try
{
  var oauthToken = await SecureStorage.GetAsync("oauth_token");
}
catch (Exception ex)
{
  // Possible that device doesn't support secure storage on device.
}

To Delete:

SecureStorage.Remove("oauth_token");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM