Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for internet access with monotouch

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.

like image 472
Jonas Stawski Avatar asked Dec 25 '09 15:12

Jonas Stawski


People also ask

How to check internet connectivity in Xamarin forms?

Open the AndroidManifest. xml file under the Properties folder and add the following inside of the manifest node. Or right click on the Android project and open the project's properties. Under Android Manifest find the Required permissions: area and check the Access Network State permission.

What is xamarin essentials?

Xamarin. Essentials provides developers with cross-platform APIs for their mobile applications. Android, iOS, and UWP offer unique operating system and platform APIs that developers have access to all in C# leveraging Xamarin. Xamarin. Essentials provides a single cross-platform API that works with any Xamarin.


1 Answers

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

like image 51
chrisntr Avatar answered Oct 08 '22 19:10

chrisntr