Welcome to the Treehouse Community
Looking to learn something new?
How to perform re login based on session expire (AFNetworking 2.0)
I'm using the singleton class pattern to instantiate AFHTTPSessionManager (AFNetworking 2.0) and do all my request, everything works perfect.
I'm storing the successful user credentials with SSKeychain and delete them when logout but as you can know sometimes the user does the log in just one time on their life (I know this approach can be handle easily when the session never expires in the server but on this one I'm using expires every 2 hours).
I was wondering if you guys know a good practice to check the session and perform a background login checking if the credentials are still on SSKeychain and a determine request is rejected by the server. I can show a MBProgressHUD and notify to the user that something is happening so he must to wait a little.
Thanks for your time.
I think I can answer to myself, since I'm getting a status code from the API I can fire a class method to perform the re-login. I can attach this method on the singleton class I've instantiate from AFHTTPSessionManager so I can use it inside the method that perform the request or whatever I want on the app.