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.
+3
A:
Using Miguel's Reachability class (found here: http://github.com/migueldeicaza/monotouch-samples/raw/master/reachability/reachability.cs) you can just call it like this:
var r = new Reachability();
if(!r.IsHostReachable("www.google.com")) {
// Put alternative content/message here
}
else
{
// Put Internet Required Code here
}
Hope this helps,
ChrisNTR
chrisntr
2009-12-25 20:03:11
Thanks, chisntr. So far this has worked on the simulator. Will update if i run into problems with the real hardware.
Jonas Stawski
2009-12-29 05:34:41
I've got an app up on the AppStore using the same code and seems to work on all devices, if you run in to any problems then let me know.
chrisntr
2009-12-30 15:22:55
A:
hi to all, this don't work on my device. But in simulator yes. I've make a simple app, for test this code. But when i make upload to device also when put disabled the wifi setting in iphone the function bool "IsHostReachable" is ever true. But, when put the iphone in to airplane mode the code work and show me alert that the connection is missed . Why ? What happen ? tnx for all..
realex
2010-04-16 07:48:02