4

This is on the top of one of my crash reports. Is there any App Launch timeout limit determined by Apple? Any common workaround if so?

Elapsed total CPU time (seconds): 13.700 (user 8.580, system 5.120), 67% CPU 
Elapsed application CPU time (seconds): 6.180, 30% CPU

On an iPhone 3G.

I have to split/delay my launching tasks maybe...

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172

1 Answers1

10

I think it has to launch within 5 (or maybe 10) seconds or the iPhone assumes it has crashed.

Try to avoid loading a lot of stuff on your main thread at launch. If you need to load a lot of stuff do it on a background thread, like this:

- (void)startLoading
{
    //call this in your app delegate instead of setting window.rootViewController to your main view controller
    //you can show a UIActivityIndiocatorView here or something if you like

    [self performSelectorInBackground:@selector(loadInBackground)];
}

- (void)loadInBackground
{
    //do your loading here
    //this is in the background, so don't try to access any UI elements

    [self performSelectorOnMainThread:@selector(finishedLoading) withObject:nil waituntilDone:NO];
}

- (void)finishedLoading
{
    //back on the main thread now, it's safe to show your view controller
    window.rootViewController = viewController;
    [window makeKeyAndVisible];
}
Nick Lockwood
  • 40,865
  • 11
  • 112
  • 103
  • I actually made an "entrance" view controller showing Default.png with a UIActivityIndicator, then laod the rest of the views on the final callback. – Geri Borbás Feb 13 '12 at 16:12
  • Just a note for people who didn't notice in the code above.... you **MUST** interact with UIKit on the main thread, so if you're currently in a background thread then you need to `performSelectorOnMainThread:` as shown above. – Jack Lawrence Feb 13 '12 at 17:56