Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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.