+(Reachability *)reachabilityForInternetConnection
{
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;
return [self reachabilityWithAddress:&zeroAddress];
}
和AFNetworkReachabilityManager
+ (instancetype)sharedManager {
static AFNetworkReachabilityManager *_sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
struct sockaddr_in address;
bzero(&address, sizeof(address));
address.sin_len = sizeof(address);
address.sin_family = AF_INET;
_sharedManager = [self managerForAddress:&address];
});
这意味着两者都建议这是检查互联网连接的正确方法。
但我认为只关心我们连接到Wifi路由器,它并不关心Wifi路由器是否可以访问互联网,对吗?
有人在How to check for network reachability on iOS in a non-blocking manner?
中说第一个测试是否可以访问google.com,而第二个 一个人只需检查是否有任何可能的互联网连接 (它认为有,即使有丢包)。
是真的吗?