婷婷同学_
我认为检查主机地址可用性的最佳方法是检查NSURL Request的结果。NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:reqURL]];NSURLResponse *resp = nil;NSError *error = nil;NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &error];NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];使用这段代码,如果您的设备无法访问提供的URL,它将为error变量提供一些输出,如果它可以访问URL Request,则错误为Nil。即使您的URL数据包可以从设备路由出去并且永远不会到达主机服务器,可到达性也会带来积极的结果。