iPhone / iPad上本地LAN Ip的可达性?

时间:2010-04-09 18:52:12

标签: iphone networking ipad

我想检查是否可以访问本地LAN上的Web服务器。我查看了Apple的Rechability Sample,但是这个示例表明所有本地的局域网都可以访问。

任何想法如何检查?

感谢的

1 个答案:

答案 0 :(得分:0)

我为此做了一个解决方法:

- (BOOL *) getOnlineState {
    BOOL *onlineState;
    NSURL *serverURL = [NSURL URLWithString:@"http://192.168.0.10:80/index.html"];
    NSURLRequest *request = [NSURLRequest requestWithURL:serverURL];
    NSURLResponse *response;
    NSError *error;
    NSData *receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    if (receivedData == nil) 
        onlineState = (BOOL *)NO;
    else
        onlineState = (BOOL *)YES;
    return onlineState;
}