gpt4 book ai didi

c# - Xamarin.Auth AccountStore 不删除值?

转载 作者:行者123 更新时间:2023-11-30 14:25:05 25 4
gpt4 key购买 nike

每当我调用我的方法从 Xamarin 中的 AccountStore 中删除某些内容时,它都会删除它并说该列表中少了一件东西。下面的方法首先从依赖服务调用。

public void DeleteSecureValue(string appName, string key)
{
var account = AccountStore.Create().FindAccountsForService(appName).FirstOrDefault();
if (account.Properties.ContainsKey(key))
account.Properties.Remove(key);

var props = account.Properties;
// when debugging, props doesn't contain a value for passcode
}

Xamarin.Forms.DependencyService.Get<IStorageHandler>().DeleteSecureValue(GlobalConstants.APP_NAME, "passcode");

var account = AccountStore.Create().FindAccountsForService(GlobalConstants.APP_NAME).FirstOrDefault();
var props = account.Properties;
// when debugging, props now has a value for passcode when it shouldn't

为什么 passcode 的值似乎又回来了?

最佳答案

您只是在 DeleteSecureValue 中操作内存中的字典。您必须将更改写回您的存储。

public void DeleteSecureValue(string appName, string key)
{
var store = AccountStore.Create();
var account = AccountStore.Create().FindAccountsForService(appName).FirstOrDefault();
if (account.Properties.ContainsKey(key))
{
account.Properties.Remove(key);
store.Save(account, appName);
}
}

关于c# - Xamarin.Auth AccountStore 不删除值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39640775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com