2009-12-25 109 views
14

如何使用MonoTouch检查互联网访问?我不在乎互联网是来自WIFI还是蜂窝网络,我只关心是否有互联网接入。使用Monoouch检查互联网访问

+1

以上链接Reachabiity类已转移到以下内容:https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs – 2011-09-13 06:21:09

回答

20

使用米格尔的可达性类(在这里找到: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 
} 

希望这有助于

ChrisNTR

+0

谢谢,chisntr。到目前为止,这已经在模拟器上起作用了。如果我遇到真正的硬件问题,将会更新。 – 2009-12-29 05:34:41

+0

我使用相同的代码在AppStore上有了一个应用程序,并且似乎适用于所有设备,如果遇到任何问题,请告诉我。 – chrisntr 2009-12-30 15:22:55

+0

我更新了链接 - 但现在示例代码将不会运行,因为该类已静态(对不起!) - 不会让人难以工作! – Stuart 2012-03-22 11:13:16