Code Operator:
self.reachability = [KSReachability reachabilityToHost:@"www.stackoverflow.com"];
actually calls the method below:
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]);
The link to SCNetworkReachability says:
The SCNetworkReachability programming interface allows you to use the application to determine the status of the current network configuration of the system and the reachability of the target host. A remote host is considered achievable when a data packet sent by an application to the network stack can leave the local device. Accessibility does not guarantee that the data packet will actually be accepted by the host.
The explanation explains that the iOS system does not send a request to the outside world to check availability. He just says that the data packet can leave the device or not. If the system was to send a request, it automatically means that it is connected to the network.
You can verify this by specifying a valid host, for example "www.stackoverflow.com", and check the charl (unlock it first) so that no request is sent. You can also check with other valid host names, for example "www.abcdefgh". com "(check this by running it in Safari and look at charles), it also gives you accessibility, but charles does not show the request. Also, if you put http: // in front of any valid host, something like" http: / /www.stackoverflow.com "this will also make it impossible to achieve. Therefore, it is clear that this is not an outgoing HTTP request. If the system should send the request outside, then what is the point of providing a class? The developer could create a network connection and try to connect to the host and see if it passes or fails.
However, it is interesting that if an invalid host is specified, such as "www.hjjkhkhkk", the iOS system gives access as false. Now the question is, how does the iOS system find a valid or invalid host without sending any requests to the outside world? Maybe this is periodically caching a list of DNS ranges? Very unlikely for me.
source share