使用monotouch检查互联网接入

Jon*_*ski 14 iphone xamarin.ios

如何使用MonoTouch检查互联网访问?我不在乎互联网是来自WIFI还是Cell Network,我关心的是是否有互联网接入.

chr*_*ntr 20

使用Miguel的Reachability类(可在此处找到:https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs),您可以这样调用它:

if(!Reachability.IsHostReachable("http://google.com")) {
    // Put alternative content/message here
}
else
{
    // Put Internet Required Code here
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助,

ChrisNTR

  • IsHostReachable方法需要一个主机,所以示例代码应该是:`if(!Reachability.IsHostReachable("google.com"))`,没有http前缀. (3认同)