简体   繁体   English

iPhone可达性给出错误的网络状态

[英]iPhone Reachability gives a wrong network status

I used the Reachability code provided by Apple sample code. 我使用了Apple示例代码提供的Reachability代码。 When I used cellular data network, it could detect that network. 当我使用蜂窝数据网络时,它可以检测到该网络。 However, once I turned it off and re-run my app again, the Reachability still gave me ReachViaWMAN (NetworkStatus) similar to the cellular network. 但是,一旦我关闭它并重新运行我的应用程序,Reachability仍然给我ReachViaWMAN(NetworkStatus)类似于蜂窝网络。 I tried reboot my iPhone with the celluar data turned off, and ran my app again. 我尝试在关闭蜂窝数据的情况下重新启动iPhone,然后再次运行我的应用程序。 The result is the Reachability couldn't reach a host. 结果是可达性无法达到主机。

I'm really confused now. 我现在真的很困惑。 How to fix this problem? 如何解决这个问题?

The Reachability code is just sample code. 可达性代码只是示例代码。 There are a number of bugs in it. 其中有许多错误。 I remember a bug where it failed when a VPN was used for example. 我记得有一个错误,该错误例如在使用VPN时失败。 I know this code is used pretty much by everyone but Apple never intended it to be some sort of official API. 我知道每个人都在使用此代码,但Apple从未打算将其用作某种官方API。

You are far better off understanding how the underlying APIs work and use those directly in your app. 您最好了解底层API的工作方式,并直接在应用程序中使用它们。 They are not difficult to use and you will catch a number of situations that Reachability does not deal with correctly. 它们并不难使用,并且您会遇到许多无法正确处理可达性的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM