当 url 连接连接超时时 iPhone 应用程序崩溃
我正在创建 iPhone 应用程序。 这样,当应用程序启动时,它会连接到服务器并下载一些图像,然后继续运行应用程序。下载应用程序时,它将显示初始启动屏幕。只要我的服务器能够 ping 通我的 iPhone,它就工作正常。 但是当我的服务器花费很长时间来响应 NSURL 请求时,问题就开始了。 该应用程序崩溃并出现以下错误:
Mon May 14 13:56:34 unknown Springboard[24] <Warning>: com.xxxx.xxx failed to launch in time
我了解到,当应用程序发生此类问题时,iPhone 会使该应用程序崩溃。我想知道 iPhone 允许应用程序响应此类实例的最长时间。
有最大值吗?
I'm creating iphone app.
In that, when the app starts, it connects to server and downloads few images and then proceeds with app. When app is downloading, it will show the initial splash screen. as long as my server is able to ping my iphone, its working well.
but the trouble starts when my server is taking much time to respond for the NSURL request.
The app is crashing with following error:
Mon May 14 13:56:34 unknown Springboard[24] <Warning>: com.xxxx.xxx failed to launch in time
I understood that when such issues happen with application, iphone crashes the appliation. I would like to know how much max time iphone allows app to respond to such instances.
Is there any max value for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
计时器大约是 20-30 秒,但这并不重要。
您正在同步下载数据。请将您的程序更改为使用 NSURLConnection 异步下载。您的应用程序看起来会更快,并且不会面临终止的风险。您还可以实现超时错误处理。
The timer is something like 20-30 seconds, but that's not important.
You are downloading data synchronously. Please change your program to download asynchronously, using NSURLConnection. Your app will seem much faster and won't run the risk of termination. You can also implement error handling for timeouts.
来自 Apple 的可达性示例上的 Readme.txt:
正如保罗所说,进行任何类型的同步网络都是一个非常非常糟糕的主意。您需要在 iPhone 上异步加载。
From the Readme.txt on Apple's Reachability example:
As Paul says, it is a very, very bad idea to do any sort of synchronous networking. You need to do this loading asynchronously on the iPhone.
如果您的请求和响应操作在主线程中处理,UI 和主线程将被阻塞,并且可能需要一些时间才能接收响应。如果主线程阻塞特定时间,看门狗将退出您的应用程序。
更好的解决方案是在后台线程或其他线程中运行您的请求。
例如
此操作在后台线程中处理
If your request and response operation handled in main thread, UI and main thread will get blocked and it may take some time to receive response. If main thread blocked for particular time the WATCH DOG will quit your application.
The better solution is run your request in background thread or some other thread.
For example
This operation handled in background thread