Login persistance with Akavache

2»

Posts

  • LalitSuranaLalitSurana INUniversity

    Thank you @Terrance @Tomasz seems it is broken for sure.

    @Tomasz do you have any suggestions on what worked for you as an alternative to Akavache.

  • OtaMaresOtaMares DEMember ✭✭
    edited August 2015

    Akavache works in our Xamarin Forms project (currently Android only), so i would not say it is broken.

    Did you install the Akavache, Akavache.Core and Akavache.sqlite3 packages? Also ensure you have installed the SQLitePCL.raw_basic package.

    Dont forget to install the packages in the PCL and platform specific project.

    Btw do you have linking enabled?

  • TektonTekton USMember ✭✭✭
    edited August 2015

    @Ota This issue I think may be specific to iOS. I'll still have to try in Android soon, just to see. Could just be PEBKAC, but last time I was looking at what Lalit is referring to, pretty sure I was covering bases.

  • someone2bsomeone2b USMember

    Did you check Tools->Options->Xamarin->Preserve Application data/cache on device between deploys?

  • HectorMenesesHectorMeneses USMember ✭✭

    As mentioned in:
    http://stackoverflow.com/questions/28294496/akavache-not-persisting-cache-data-between-app-restarts/41577919#41577919

    For Xamarin Forms apps this is what worked for me:

    • Install SqlLite3 in PCL, iOS and Android projects
    • Install Akavache in PCL, iOS and Android projects
    • Override OnStart
      protected override void OnStart() {
      // Handle when your app starts
      BlobCache.ApplicationName = "AppName";
      BlobCache.EnsureInitialized();
      }

    -Apply the suggestion from mainagioia ( see link above )
    Preserve application data/cache on device between deploys in the settings

  • It's old post, but the solution for first question is really simple:

    protected async override void OnStart (){

        base.OnStart ();
    
        try{
            _u = await BlobCache.UserAccount.GetObject<User>("User"); // this will throw if there is no key user
        }catch(Exception e){
            // no User key
        }
    
    
        if (_u != null) 
        {
            MessagingCenter.Send<User>(_u, "Authorized");
        }
    }
    

    }
    or

    protected override void OnStart ()    {
        base.OnStart ();
    
        BlobCache.UserAccount.GetObject<User>("User")
                .Subscribe(x =>{
                    _u = x;
                    if (_u != null) 
                    {
                        MessagingCenter.Send<User>(_u, "Authorized");
                    }               
                }, ex => Console.WriteLine("No Key!"));        
    }
    

    Observables are asynchronous.

  • batmacibatmaci DEMember ✭✭✭✭

    @KrzysztofSkowronek.7608 said:
    It's old post, but the solution for first question is really simple:

    protected async override void OnStart (){

    base.OnStart ();

      try{
          _u = await BlobCache.UserAccount.GetObject<User>("User"); // this will throw if there is no key user
      }catch(Exception e){
          // no User key
      }
      
    
        if (_u != null) 
        {
            MessagingCenter.Send<User>(_u, "Authorized");
        }
    }
    

    }
    or

    protected override void OnStart () {
    base.OnStart ();

        BlobCache.UserAccount.GetObject<User>("User")
                .Subscribe(x =>{
                  _u = x;
                  if (_u != null) 
                  {
                      MessagingCenter.Send<User>(_u, "Authorized");
                  }               
              }, ex => Console.WriteLine("No Key!"));        
    }
    

    Observables are asynchronous.

    I get a crash when I use it onStart of app. it doesnt even throw exception although i have try catch like yours but crashes the application with the exception as I posted here https://github.com/akavache/Akavache/issues/392

2»
Sign In or Register to comment.