如何在iPhone中使用Reachability代码查找服务器? [英] How to find server is reachable with Reachability code in iPhone?

查看:125
本文介绍了如何在iPhone中使用Reachability代码查找服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有客户端服务器说http://abc.com,我想检查此服务器是否响应。

如何使用可达性代码检查来自苹果?

因为我看到了代码,但无法在哪里写我的客户端的网址来检查这个。

请建议我。


I have client server say "http://abc.com" and i want to check whether this server responding or not.
How to check this with Reachability code from apple?
As i see that code but not able to get where to write my client's url to check this.
Please suggest me.

推荐答案

这是一个同步的例子。您可能希望异步执行此操作,但这将帮助您快速检查。

Here's a synchronous example. You'll probably want to do this asynchronously, but this will get you through for a quick check.

Reachability *netReach = [Reachability reachabilityWithHostName:@"host.name"];
//return [netReach currentReachabilityStatus];
NetworkStatus netStatus = [netReach currentReachabilityStatus];
if (netStatus==ReachableViaWiFi) {
    [ViewManager showStatus:@"Reachable (WiFi)!"];
} else if(netStatus==ReachableViaWWAN) {
    [ViewManager showStatus:@"Reachable (WWAN)!"];
} else {
    [ViewManager showStatus:@"Not reachable, aww :-("];
}

使用reachabilityWithHostName时,你必须记住这只是主机名,不应该有http://前缀等。

When using reachabilityWithHostName you have to remember that this is just the host name, there should be no http:// prefix or the like.

这篇关于如何在iPhone中使用Reachability代码查找服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆