Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

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.

1 Answer

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.