Check for internet access with monotouch

2019-02-12 05:03发布

问题:

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