iOS 网络可达性 - 似乎不起作用

发布于 2024-11-05 07:56:48 字数 586 浏览 0 评论 0原文

我正在关注 如何检查活动iOS 或 OSX 上有互联网连接吗?http ://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html 来测试连接性,但遇到了一些非常基本的问题。

例如,我在另一台计算机上运行 .NET API,然后尝试通过我的 mac mini 连接到它。

1) 当 IIS 运行时,一切都按预期工作,我很高兴我能做到这一点!

2)我可以完全关闭IIS(显然,主机无法访问),但我的reachabilityWithHostName仍然报告主机可以访问。

有什么想法吗?

I'm following How to check for an active Internet connection on iOS or OSX? and http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html to test for connectivity, but am running into some pretty basic issues.

For example, I'm running a .NET API off of another machine and then trying to connect to it via my mac mini.

1) When IIS is running, everything is working like it should, I was excited that I got this working!

2) I can shut off IIS completely (obviously, host is unreachable) but my reachabilityWithHostName is still reporting that the host is reachable.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆之渊 2024-11-12 07:56:48

请参阅 SCNetworkReachability 参考

SCNetworkReachability 编程
接口允许应用程序
确定系统的状态
当前网络配置和
目标主机的可达性。 A
远程主机被认为是可达的
当数据包由
应用程序进入网络堆栈,
可以离开本地设备。
可达性并不能保证
数据包实际上是
主机收到。

打开和关闭 IIS 只是阻止您的服务器接收 ftp/http 等 Web 请求,并不会阻止设备成功发送数据包。

See the SCNetworkReachability Reference.

The SCNetworkReachability programming
interface allows an application to
determine the status of a system's
current network configuration and the
reachability of a target host. A
remote host is considered reachable
when a data packet, sent by an
application into the network stack,
can leave the local device.
Reachability does not guarantee that
the data packet will actually be
received by the host.

Turning IIS on and off is just preventing your server from receiving web request such as ftp/http and does not stop the device from successfully sending a data packet out.

笔落惊风雨 2024-11-12 07:56:48

不久前我用这个答案来解决我的问题。我找到了一个更好的解决方案,并将其发布在这里,供其他可能认为它有帮助的人使用。

Apple 提供了一个很好的示例代码。

此处下载示例代码,

包含 Reachability.h和 Reachability.m 文件在您的项目中。查看 ReachabilityAppDelegate.m,了解如何确定主机可达性、通过 WiFi、WWAN 等可达性的示例。为了非常简单地检查网络可达性,您可以执行以下操作

Reachability *networkReachability = [Reachability reachabilityForInternetConnection];   
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];    
if (networkStatus == NotReachable) {        
    NSLog(@"There IS NO internet connection");        
} else {        

     NSLog(@"There IS internet connection");        


    }        
}

A while ago I used this answer to solve my problem. I found a better solution and I am posting it here for others who may find it helpful.

There is a nice sample code provided by Apple.

Download the sample code here

Include the Reachability.h and Reachability.m files in your project. Take a look at ReachabilityAppDelegate.m to see an example on how to determine host reachability, reachability by WiFi, by WWAN etc. For a very simply check of network reachability, you can do something like this

Reachability *networkReachability = [Reachability reachabilityForInternetConnection];   
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];    
if (networkStatus == NotReachable) {        
    NSLog(@"There IS NO internet connection");        
} else {        

     NSLog(@"There IS internet connection");        


    }        
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文