Xamarin.Auth: Account data not persisted when app is updated

 ̄綄美尐妖づ 提交于 2020-01-03 19:01:06

问题


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;
    }
}

回答1:


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"

There should be a similar setting if you are using Visual Studio.



来源:https://stackoverflow.com/questions/19832940/xamarin-auth-account-data-not-persisted-when-app-is-updated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!