iPhone 在启动画面时崩溃

发布于 2024-08-12 22:16:24 字数 854 浏览 1 评论 0原文

我有一个应用程序,打开时会显示启动/加载屏幕。我将其设置为应用程序继续运行前 2.5 秒。

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

sleep(2.5);


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

}

我现在希望应用程序在启动屏幕上暂停一分钟(这是有充分理由的),所以我想:

sleep(60.0);

可以使用。不过,当我使用此功能时,我的应用程序会打开并在启动屏幕上停留大约 20 秒,然后退出/崩溃回到跳板。

知道为什么会这样吗?

我该怎么做?

编辑//值得注意的是:

sleep(15.0);

sleep(19.0);

工作。

sleep(20.0);

没有。

解决方案 // 不要使用睡眠,使用计时器。我在这里遵循教程:

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

非常感谢,

斯图

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

合约呢 2024-08-19 22:16:24

我在这里纯粹是猜测,但可能是这样,因为你阻塞了主线程(使用睡眠而不是计时器),iPhone操作系统将其视为“无响应的应用程序”并杀死它。

查看 NSTimer。

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.

最冷一天 2024-08-19 22:16:24

我同意 Joshua Nozzi 的观点,即操作系统“认为”您的应用程序已崩溃。

我会删除 sleep() 并执行此操作:

[window performSelector:@selector(addSubview:) withObject:viewController.view afterDelay:60.0f];
[window performSelector:@selector(makeKeyAndVisible) withObject:nil afterDelay:60.0f];

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];
背叛残局 2024-08-19 22:16:24

如果您查看控制台,您可能会看到类似以下内容的内容......

警告:您的应用程序名称未能及时启动

警告:强制报告您的应用程序名称的崩溃...

警告:已完成崩溃报告。

基本上,因为您将主线程置于睡眠状态太长时间,操作系统决定应用程序无法启动并强制应用程序退出。您最好使用计时器来进行延迟,以便主线程保持活动状态。

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.

暮倦 2024-08-19 22:16:24

我建议您以不同于当前残酷逻辑的方式实现启动屏幕逻辑:)

也许,您可以创建一个覆盖整个屏幕的 UIView,在触摸时或超时后,自毁(removeFromSuperview)?

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

记忆で 2024-08-19 22:16:24

嗯,没有充分的理由让 iPhone 应用程序休眠 60 秒。绝不。愿您当前形式的应用程序永远不会到达 App Store! :)

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

熟人话多 2024-08-19 22:16:24

看一下这篇博客文章,它描述了如何创建一个淡出的启动屏幕,您应该能够设置日志可见的延迟时间。查看计时器是在哪里创建的。

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

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/

初相遇 2024-08-19 22:16:24
    [NSThread sleepForTimeInterval:0.85];

我想你可以使用这个方法。

    [NSThread sleepForTimeInterval:0.85];

I think u can use this method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文