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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With