我想对此进行完全相同的实现,但我在Xamarin MvvmCross中。
你可以尝试使用: https://github.com/has-taiar/KeyChain.Net
它使用每个平台的本机实现,因此您无需考虑存储登录信息的位置,它将始终存在于每个平台上最安全的位置。
语法简单明了:
苹果示例
var helper = new KeyChain.Net.XamarinIOS.KeyChainHelper();
var isSaved = helper.SetKey("myKey", "myKeyValue");
var keyValue = helper.GetKey("myKey");
var isDeleted = helper.DeleteKey("myKey");
安卓示例:
var helper = new KeyChain.Net.XamarinAndroid.KeyChainHelper(myActivity, "myKeyProtectionPassword");
var isSaved = helper.SetKey("myKey", "myKeyValue");
var keyValue = helper.GetKey("myKey");
var isDeleted = helper.DeleteKey("myKey");
WP示例:
var helper = new KeyChain.Net.XamarinWinRT.KeyChainHelper();
var isSaved = helper.SetKey("myKey", "myKeyValue");
var keyValue = helper.GetKey("myKey");
var isDeleted = helper.DeleteKey("myKey");