Reachability示例代码中的SCNetworkReachabilityGetFlags需要很长时间才能返回 [英] SCNetworkReachabilityGetFlags in Reachability sample code takes too long to return

查看:363
本文介绍了Reachability示例代码中的SCNetworkReachabilityGetFlags需要很长时间才能返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPhone4上使用iOS4.1。我也在使用最新版本的Reachability代码。我的设备没有连接,但似乎代码等待超时,否则设备需要很长时间才能报告可达性状态。

I'm using iOS4.1 on an iPhone4. I'm also using the latest version of the Reachability code. My device doesn't have a connection but it seems like the code waits to timeout or else the device takes ages to report back about the reachability status.

这似乎不会发生在使用iPhone3gs的iOS4.0.1上。

this doesn't seem to happen on iOS4.0.1 using iPhone3gs.

有没有其他人遇到这个?除了开始一个新线程之外,有什么方法可以绕过它吗?

Has anyone else come across this? Any way to get around it other than starting a new thread?

推荐答案

你确定你是异步使用它吗?

Are you sure you're using it asynchronously?

来自Apple的文档ReadMe.txt on Reachability项目:

From Apple's docs ReadMe.txt on the Reachability project:


可达性示例演示
异步使用
SCNetworkReachability API。您可以同步使用
API,但不要
在主线程上通过hostName
发出同步检查。如果设备
无法到达DNS服务器或在
慢速网络上,同步调用
SCNetworkReachabilityGetFlags
函数可以阻止最多30
秒尝试解析
hostName。如果在主
线程上发生这种情况,那么应用程序监视程序将在$ 20 $
不活动后杀死应用程序。

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.

所以,我认为你是对的 - 开始一个后台线程来处理它。

So, I think you're right - start a background thread to handle it.

这篇关于Reachability示例代码中的SCNetworkReachabilityGetFlags需要很长时间才能返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆