0

In my app, I currently have a UITabBarViewController as the initial VC. I also have an HTTP GET request giving me feedback on whether or not the user is logged in. Obviously, if they're not logged in, I need to redirect my initial VC to my LoginHomeViewController.

I've been trying to set this up by using response logic in my AppDelegate.m's application didFinishLaunchingWithOptions: method, but should I be using this logic in my FIRST tab bar controller, perhaps in a viewWillAppear method? Pros and Cons? Possible recursions to either?

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
Chisx
  • 1,976
  • 4
  • 25
  • 53
  • Why not create a simple UIViewController which is responsible for the login and when you login segue to your TabBarViewController? – Eli Braginskiy Jan 03 '14 at 07:31
  • Check my answer here **http://stackoverflow.com/questions/16351348/example-for-login-screen-modally-based-on-storyboard/16351631#16351631**. Hope it helps – Kumar KL Jan 03 '14 at 07:48
  • Kumar, this would've helped about 4 hours ago, before i switched things around so that my initial view controller is the UITabBarViewController. Now that things are switched around, I just need to present the login page conditionally from a viewWillAppear inside my first tab bar VC – Chisx Jan 03 '14 at 07:57

1 Answers1

1

You should be setting this thing in viewWillAppear method of your root view controller. From appDelegate you should be setting home or root view controller as root view controller for self.window

There you could be checking the access token or if the login credentials were verified if not verified you can either present or push login view controller

Deepesh
  • 8,065
  • 3
  • 28
  • 45
channi
  • 1,028
  • 9
  • 16
  • you're right.. that's what I'm currently setting up right now, however, I had forgotten about setting the root view Controller. Once I have set the root view controller, the self.view.rootviewcontroller will work correctly for the present, right? – Chisx Jan 03 '14 at 07:40
  • Yes this is what i would be doing – channi Jan 03 '14 at 07:47
  • Sorry, but do you know where I can find out how to set the UITabBarVC to the root view controller in AppDelegate?? – Chisx Jan 03 '14 at 08:03
  • just set [self.window setRootViewController:tabbarcontrollerVC]; – channi Jan 03 '14 at 08:07
  • I hate to be so noob, but do I need to create a class to identify the Tab bar controller or can I just use storyboard ID?, b/c I can't cmd+drag from TabBarVC to AppDelegate.h to create the property.. – Chisx Jan 03 '14 at 08:14
  • yes ..but remember ..if you do it from `viewWillAppear`. everytime that method is called. it will repeat the same stuff. So u better have some check there – devluv Jan 03 '14 at 08:16
  • Sorry, I have not used storyboards yet for setting tabbarcontroller as root view – channi Jan 03 '14 at 08:16
  • It will only present login VC in case the access token is not there in the app, like when you call login web service it will be sending back some access token or anything else to confirm the successful login, that token can be saved in NSUserDefaults which can be checked there in viewWillAppear method – channi Jan 03 '14 at 08:19
  • So I need to avoid sending the get request in the viewWillAppear, and instead, use the didFinishLaunchingWithOptions in my **AppDelegate** to send the GET, also saving the token, then use the token for the logic in viewWillAppear? – Chisx Jan 03 '14 at 08:24
  • no not necessary see when you will present the login view controller you can dismiss/pop the login view controller after you get the token and you can save it at same time – channi Jan 03 '14 at 18:05