How can I check internet access with MonoTouch? I don't care if the internet comes from a WIFI or the Cell Network, all I care is whether there is internet access or not.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Using Miguel's Reachability class (found here: https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs) you can just call it like this:
if(!Reachability.IsHostReachable("http://google.com")) {
// Put alternative content/message here
}
else
{
// Put Internet Required Code here
}
Hope this helps,
ChrisNTR