Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top