0

I have read the apple guidelines and I know it says you shouldn't do that but hear me out as I would like to know if what I am doing is bad practice.

When my application loads up, in the app delegate, a web call is made which sets up the order of the tabs, as well the content within it. Web call is like this

WebCalls *wc = [[WebCalls alloc] init];
[wc setWebCallDidFinish:^(NSString * json) {    
    // set up tab order here, as well as stores the JSON in a file on the phone
    // Also code here to download images and cache them on phone
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
}
[wc getData:phoneNumber];

Now this code works great but the problem is what will happen when app starts is

  1. Launch image shows for a second (which is not very long, sometimes it's half a second or less so just annoying)
  2. Screen goes black for about 2 seconds while json is parsed and images downloaded etc
  3. Then first tab controller is shown

What I want is a seamless transition between the splash screen and the first screen so the user never sees black screen.

What I was thinking of doing is something like this

Change iPhone splash screen time

In the answer given, the guy pushes a view forward to be the splash screen. Would it be bad practice to push that view forward, and then in that screen do the web calls which gets json data, and downloads images, then dismiss the view and have the tabcontroller view become main view?

Or how else would I prevent this delay? Is it bad practice to have a large enough web call like this in AppDelegate?

If this is bad practice to push a view forward while doing background loading, what else would you recommend? Would it be better if I just make the tabController the main rootViewController first and do the webCall in the first tab shown instead, then update the tabs when this web call finished? I was considering this one, but the tab order could be in any order after the web call is made, so not sure what tab will be shown first.

Would be grateful for your input

Community
  • 1
  • 1
AdamM
  • 4,400
  • 5
  • 49
  • 95

1 Answers1

2

In the answer given, the guy pushes a view forward to be the splash screen. Would it be bad practice to push that view forward, and then in that screen do the web calls which gets json data, and downloads images, then dismiss the view and have the tabcontroller view become main view?

This is the way to do it. It's generally bad practice to download stuff from applicationDidFinishLaunching, what happens if the phone is not connected to the internet?

Present a simple view controller (using presentModalViewController:controller animated:NO with a UIActivityIndicator and a label describing what's going on, and then dismiss it when loading finishes (or it it fails, just display an error and deny access to the app). Remember to also check for airplane mode and notify the user.

Hampus Nilsson
  • 6,692
  • 1
  • 25
  • 29
  • And Apple are okay with this technique? Just want some confirmation before I start coding this as I read a lot of different opinions on this, and got a bit confused as some people were saying yes others were saying no, so wasn't sure – AdamM May 21 '12 at 15:10
  • Yes, as long as you do the loading in the background (ie. don't freeze the main thread) and display appropriate error messages they should have no issues with this. Tons of app makes use of this technique. – Hampus Nilsson May 21 '12 at 15:14