SCNetworkReachabilityGetFlags in Reachability sample code takes too long to return

霸气de小男生 提交于 2019-12-01 08:38:54

问题


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.

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?


回答1:


Are you sure you're using it asynchronously?

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

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.



来源:https://stackoverflow.com/questions/4461238/scnetworkreachabilitygetflags-in-reachability-sample-code-takes-too-long-to-retu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!