我正在使用Xamarin Essentials添加安全存储,但每次我尝试保存在通用Windows平台(UWP)上时应用程序都会保持冻结(没有错误)。有人可以解释为什么它会冻结吗?
注意:我在Android设备上使用它没有任何问题。
try
{
await SecureStorage.SetAsync("username", Username.Text);
await SecureStorage.SetAsync("password", Password.Text);
}
catch (Exception){}
根据这个form,在UWP上使用安全存储之前不需要设置。
线程被锁定所以我不得不添加Device.BeginInvokeOnMainThread
所以代码最终看起来像这样:
try
{
Device.BeginInvokeOnMainThread(async () =>{
await SecureStorage.SetAsync("username", Username.Text);
await SecureStorage.SetAsync("password", Password.Text);
});
}
catch (Exception){}