Xamarin.Auth:更新应用程序时不会保留帐户数据 [英] Xamarin.Auth: Account data not persisted when app is updated
问题描述
我正在使用 Xamarin.Auth 对 Foursquare 等服务进行身份验证.我的身份验证代码一切正常,问题是当我部署新版本的应用程序时,帐户数据没有保留 - 每次我在手机上部署测试版本时,我都必须重新进行身份验证.
I'm using Xamarin.Auth to authenticate with services like foursquare and so. I've gotten my authentication code working all good, the problem is that the account data is not persisted when I deploy a new version of my app - each time I deploy a test version on the phone, I've to re-authenticate.
这是我存储帐户的方式;
Here's how I store the account;
/// <summary>
/// Stores the account.
/// </summary>
private void StoreAccount(AuthenticatorCompletedEventArgs eventArgs)
{
if (!eventArgs.IsAuthenticated) // make sure we are authenticated.
{
Log.Debug(Logging.AppTag, "FourSquareClient can't store account as auth. is cancelled. ");
return;
}
this.IsAuthenticated = true;
this.Account = eventArgs.Account;
AccountStore.Create(this.OwnerContext).Save(eventArgs.Account, "Foursquare");
}
这是我检查我们是否有存储帐户的方法;
and here is how I check if we have a stored account;
/// <summary>
/// Retrieves stored account.
/// </summary>
private void RetrieveAccount()
{
if (this.IsAuthenticated)
{
Log.Debug(Logging.AppTag, "FourSquareClient is already authenticated! ");
return;
}
var accounts = AccountStore.Create(this.OwnerContext).FindAccountsForService("Foursquare");
var enumerable = accounts as IList<Account> ?? accounts.ToList();
if (enumerable.Any())
{
Log.Info(Logging.AppTag, "Foursquareclient found account data.");
this.IsAuthenticated = true;
this.Account = enumerable.First();
}
else
{
Log.Info(Logging.AppTag, "Foursquareclient no account data found!");
this.IsAuthenticated = false;
this.Account = null;
}
}
推荐答案
默认行为是每次部署应用程序时重置您的 Android 设置.为了防止这种情况,在 Xamarin Studio --> 首选项 --> Android --> 选中在应用程序部署之间保留数据/缓存"
The default behavior is for your Android settings to get reset every time the app is deployed. To prevent this, in Xamarin Studio --> Preferences --> Android --> check "Preserve data/cache between application deploys"
如果您使用的是 Visual Studio,应该也有类似的设置.
There should be a similar setting if you are using Visual Studio.
这篇关于Xamarin.Auth:更新应用程序时不会保留帐户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!