I have a tab view controller app which will require to show a login view controller when the user is logged out - when he opens the application for the first time or after he logs out.
What is the best approach? where should I put the code which checks for the session and displays the login view controller?
AppDeledate? one of the tabs? A class for the Tab Bar Controller?
I'm looking for some best practices or a working example of such behaviour.
Thanks!
Singelton
design is a good approach. For for a login use case, you really need not have to have a singelton
. You can still go with Observer
design pattern. Singleton
is really nice while using CoreData or persistent storage or many operations that needs a common unique controller across the app.
Here is how you can implement the Observer
pattern.
LoginViewController
. viewDidLoad
of each TabBarController items, perform the Session validity Check.This is far simpler approach. In combination with Singleton
, the Observer
pattern provides you a robust scalable approach.
Updated Code
----------------------------------------------------------
Please find LoginObserver
Code here
----------------------------------------------------------
Hope that helps.