iOS 网络可达性 - 似乎不起作用
我正在关注 如何检查活动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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅 SCNetworkReachability 参考。
打开和关闭 IIS 只是阻止您的服务器接收 ftp/http 等 Web 请求,并不会阻止设备成功发送数据包。
See the SCNetworkReachability Reference.
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.
不久前我用这个答案来解决我的问题。我找到了一个更好的解决方案,并将其发布在这里,供其他可能认为它有帮助的人使用。
Apple 提供了一个很好的示例代码。
此处下载示例代码,
包含 Reachability.h和 Reachability.m 文件在您的项目中。查看 ReachabilityAppDelegate.m,了解如何确定主机可达性、通过 WiFi、WWAN 等可达性的示例。为了非常简单地检查网络可达性,您可以执行以下操作
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