我使用AFNetworkReachabilityManager检查互联网连接的状态。 它适用于以下情况:
Wifi is turned 'ON'
Wifi is turned 'OFF'
但当用户为connected to a wifi network without active internet connection
时
它仍然会返回状态为“可达”'
self.manager = [AFNetworkReachabilityManager managerForDomain:@"https://www.google.com"];
[self.manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status)
{
if (status == AFNetworkReachabilityStatusNotReachable)
{
[weakSelf.statusLabel setText:@"Not Connected"];
}
else
{
[weakSelf.statusLabel setText:@"Connected"];
}
}];