开发者

Crash At Splash Screen, iPhone

开发者 https://www.devze.com 2022-12-12 19:02 出处:网络
I have an app which when opened, displays a splash/loading sc开发者_如何学JAVAreen. I had this set at 2.5 seconds before the app moved on.

I have an app which when opened, displays a splash/loading sc开发者_如何学JAVAreen. 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


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.


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];


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.


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)??


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! :)


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/


    [NSThread sleepForTimeInterval:0.85];

I think u can use this method.

0

精彩评论

暂无评论...
验证码 换一张
取 消