当 url 连接连接超时时 iPhone 应用程序崩溃

发布于 2024-09-02 11:37:40 字数 384 浏览 3 评论 0原文

我正在创建 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 技术交流群。

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

发布评论

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

评论(3

黯淡〆 2024-09-09 11:37:40

计时器大约是 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.

情徒 2024-09-09 11:37:40

来自 Apple 的可达性示例上的 Readme.txt:

可达性示例演示了
的异步使用
SCNetworkReachability API。您可以使用
同步API,但不
按主机名发出同步检查
在主线程上。如果设备
无法到达 DNS 服务器或位于
网络速度慢,同步调用
SCNetworkReachabilityGetFlags
函数最多可阻塞 30 个
尝试解决问题的秒数
主机名。如果这种情况发生在主
线程,应用程序看门狗将
20秒后杀死应用程序
不活动。

正如保罗所说,进行任何类型的同步网络都是一个非常非常糟糕的主意。您需要在 iPhone 上异步加载。

From the Readme.txt on Apple's Reachability example:

The Reachability sample demonstrates
the asynchronous use of the
SCNetworkReachability API. You can use
the API synchronously, but do not
issue a synchronous check by hostName
on the main thread. If the device
cannot reach a DNS server or is on a
slow network, a synchronous call to
the SCNetworkReachabilityGetFlags
function can block for up to 30
seconds trying to resolve the
hostName. If this happens on the main
thread, the application watchdog will
kill the application after 20 seconds
of inactivity.

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.

酒绊 2024-09-09 11:37:40

如果您的请求和响应操作在主线程中处理,UI 和主线程将被阻塞,并且可能需要一些时间才能接收响应。如果主线程阻塞特定时间,看门狗将退出您的应用程序。

更好的解决方案是在后台线程或其他线程中运行您的请求。

例如

   if(!backgroundQueue)
    backgroundQueue=[[NSOperationQueue alloc]init];

NSURLRequest *request=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:url]
                                           cachePolicy:NSURLCacheStorageNotAllowed
                                       timeoutInterval:60];

[NSURLConnection sendAsynchronousRequest:request
                                   queue:backgroundQueue
                       completionHandler:^(NSURLResponse *response,NSData *data,NSError *error) {
    if (complete) {
           // handle your logic here
    }
}];

此操作在后台线程中处理

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

   if(!backgroundQueue)
    backgroundQueue=[[NSOperationQueue alloc]init];

NSURLRequest *request=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:url]
                                           cachePolicy:NSURLCacheStorageNotAllowed
                                       timeoutInterval:60];

[NSURLConnection sendAsynchronousRequest:request
                                   queue:backgroundQueue
                       completionHandler:^(NSURLResponse *response,NSData *data,NSError *error) {
    if (complete) {
           // handle your logic here
    }
}];

This operation handled in background thread

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