【发布时间】:2010-11-01 16:15:00
【问题描述】:
我只需要检查与 IP 地址的连接。我正在尝试使用reachabilityWithAddress 选项使用Apple Reachability 类来做到这一点。我的问题是我可以在 callAddress.sin_addr.s_addr 字段中输入任何 IP 地址,并且 statusText 总是“可达”。如何准确检查与 IP 地址的连接?
-(BOOL)reachabilityTest {
struct sockaddr_in callAddress;
callAddress.sin_len = sizeof(callAddress);
callAddress.sin_family = AF_INET;
callAddress.sin_port = htons(24);
callAddress.sin_addr.s_addr = inet_addr("212.83.3.190");
Reachability *hostReach = [[Reachability reachabilityWithAddress:&callAddress] retain];
NetworkStatus netStatus = [hostReach currentReachabilityStatus];
if (netStatus == NotReachable)
{
NSLog(@"NotReachable");
statusField.text = @"NOT reachable";
return NO;
}
if (netStatus == ReachableViaWiFi)
{
NSLog(@"ReachableViaWiFi");
statusField.text = @"reachable";
return YES;
}
[Reachability release];
}
【问题讨论】:
标签: iphone sdk reachability