Reachability lying about disconnected wifi network

2019-05-22 01:07发布

I use Stackmob SDK (which will end soon) and I assume they use AFNetworking for reachability. If a device is connected to a wifi network which is disconnected from the Internet, the reachability check will be positive and the following statement will be true:

if ([self.appDelegate.client.networkMonitor currentNetworkStatus] == SMNetworkStatusReachable) {
    // reachable
}

How can I fine tune this check to overcome the present limitation? How can I check for real network reachability within this if statement, or is there any better Reachability check out there?

1条回答
贼婆χ
2楼-- · 2019-05-22 01:44

If your question is "can I send data to that host and receive a response", then Reachability can only answer "no" or "maybe". It cannot answer "yes" because there are many connectivity factors that Reachability does not check.

Reachability only checks the first hop. It defines reachability as the ability for packets to leave the device in the direction of that host. If the device is connected to a network that claims to be able to route to that host then Reachability is satisfied. If the router is lying or the host is down or there are unfriendly backhoes in Kansas then Reachability's result will be optimistic.

The only sure way to answer the question "can I send data to that host and receive a response" is to actually attempt to send data to that host and receive a response. Reachability can help you give up when connectivity is definitely not available. If you try and fail, Reachability's network-change notifications can help you decide when to try again without wasting power.

查看更多
登录 后发表回答