1

I try to explain my problem. In appdelegate I have to select a rootViewController depending on the result of an asynchronous request (I'm using AFNetworking framework). In fact, I need to know if my user is profiled or not: if he is profiled I can show him app's Home, if he is not I have to show him a profilation view.

In storyboard I set the Home view as the designated entry point, but in this way this view is always shown until the asynchronous request is completed. Is there a way to make appdelegate wait for the response?

Hrqls
  • 2,944
  • 4
  • 34
  • 54
Luciano
  • 1,208
  • 2
  • 17
  • 36

4 Answers4

4

I think there is't good solution to let app delegate wait for the response because if the network connection will be poor the app loading time will be very long and OS could kill your app or user can turn it off.

You can add some loading view controller (with animation so user will know that the app is doing something) instead of home one and when you receive the response present appropriate view to the user (modal segue could do the job). Hope this help

Greg
  • 25,317
  • 6
  • 53
  • 62
  • I've thought about using a splash screen, but I read in Apple's guide that is better to avoid it. However I don't see any alternative right now... I'll wait for some other answer before accepting your. – Luciano Jun 04 '14 at 13:29
  • What do you mean by splash screen, if you think about the loading screen (you can see just before the root one will appear) it appeares just for a sec. If you do some sync work which take long time the screen will stay for that long but it will take too much os will turn the app off). The my solution you can use, just instead of animation on the load screen add static image and it will behave as splash screen. – Greg Jun 04 '14 at 13:37
3

A better solution is to use splash screens. That is when your app gets loaded in AppDelegate, create and push a splash view controller. Which would just contain a single UIImageView covering whole screen showing your application splash image. Upon asynchronous call completion, pop that splash view controller and push your required view Controller.

Many apps use this way to download necessary asynchronous data before showing the app. So that user don't see empty screens or garbage data.

If something gets failed like internet connectivity failure or server response error, etc., Show error to user and perform error handling according to your app logic.

Salman Zaidi
  • 9,342
  • 12
  • 44
  • 61
0

You can programatically navigate to the root view controller as

[self.navigationController popToRootViewControllerAnimated:YES];

This code can be put in the condition of result.

Or in your way, I think you are created a segue for navigation to the rootViewController. You can programatically perform a segue using

- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
manujmv
  • 6,450
  • 1
  • 22
  • 35
0

If you are using the AFNetworking, just add a method in the success block and pass the response to that method in a parameter of dictionary. Check your response in the method and choose the controller which you want to make make the root view controller from that method.

Manpreet Singh
  • 181
  • 1
  • 9