views:

463

answers:

7

Hi there,

I have an app which when opened, displays a splash/loading screen. I had this set at 2.5 seconds before the app moved on.

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{

sleep(2.5);


[window addSubview:viewController.view];
[window makeKeyAndVisible];

}

I now want the app to pause at the splash screen for a minute (there is a very good reason for this) so I thought:

sleep(60.0);

could be used. When I use this though, my app opens and stays at the splash screen for about 20 seconds, before quitting/crashing back to the springboard.

Any idea why this is the case?

How should I do this?

Edit // It is worth noting both:

sleep(15.0);

and

sleep(19.0);

work.

sleep(20.0);

does not.

Solution // Do not use sleep, use timer. I followed tutorial here:

http://adeem.me/blog/2009/06/22/creating-splash-screen-tutorial-for-iphone/

Many thanks,

Stu

+4  A: 

I'm purely guessing here, but it may be that, because you're blocking the main thread (using sleep instead of a timer), the iPhone OS is seeing that as an "unresponsive app" and killing it.

Check out NSTimer.

Joshua Nozzi
+3  A: 

If you look in your console you will probably see something like the following...

Warning: your application name failed to launch in time

Warning: Forcing crash report of your application name...

Warning: Finished crash reporting.

Basically, because you've put the main thread to sleep for too long the OS decides that the application failed to launch and forces the app to exit. You would be better of using a timer to do the delay so that the main thread remains active.

Paul
A: 

I would suggest you implement the Splash screen logic differently than the current cruel one :)

perhaps, you could create a UIView covers the whole screen, upon touch or after a timeout, self destructs (removeFromSuperview)??

Prakash
A: 

Um, there is never a good reason for sleeping an iPhone app for 60s. Never. May your app in its current form never reach the App Store! :)

Jonathan Sterling
That is not the intent for my app, I am just learning and creating this app is for enjoyment, practise and fun. Thanks for the advice though, maybe in the future my apps will make it to the app store!
Stumf
Oh, OK. The best of luck to you!
Jonathan Sterling
A: 

Have a look at this blog entry that describes how to create a splash screen that will fade out and you should be able to set the delay time for how log it will be visible. Look where the timer is created.

http://icodeblog.com/2009/03/18/iphone-game-programming-tutorial-part-3-splash-screen/

epatel
+4  A: 

I agree with Joshua Nozzi, that the OS "thinks" that your app has crashed.

I'd remove the sleep() and do this instead:

[window performSelector:@selector(addSubview:) withObject:viewController.view afterDelay:60.0f];
[window performSelector:@selector(makeKeyAndVisible) withObject:nil afterDelay:60.0f];
Thomas Müller
A: 
 [NSThread sleepForTimeInterval:0.85];

I think u can use this method.

shilpa