Best way to check internet connectivity (Android + iOS)

We’re developing an app, which has to maintain an internet connection to communicate with our Smartfox servers. Before connecting to our Smartfox, we need to know if there’s a stable internet connection. We have tried several approaches, Ping, WWW, Application.internetReachability, but we haven’t found a profound solution that runs great on both our release platforms (Android & iOS)

Maybe we’re missing something here, but in our case, the Ping solution would be the most logical, since we can Ping directly to the IP-adress of our Smartfox-servers, but this approach has given us a lot of headaches, because it’s really unpredictable on Android.

Any help/tips are greatly appreciated, just bear in mind that we have to have a continuous check if we are connected to the internet (not just LAN)

Thanks in advance

btw: we’re using Unity 3.5.7f6

I ran into the same problem. I ended up just using hs_get to contact my database server and made a small script on it that simply returned a 0 when ran, so in Unity if I got a zero back, I was connected to the internet, if I got a null or anything else back, I was not. Worked for Android where ping failed.

(Adding a comment to an old posting in case somebody finds this using search…)

Indeed a working way is to make a WWW query with a known answer. This is called “captive portal detection” in operating systems, to verify if login WWW page should be presented to an user. This happens when a user connects to a network with a login page to gate actual access to internet.

I have made an easy asset called Internet Reachability Verifier for Unity, which implements this technique, offering chance to use one of the verification URLs from the big OS vendors or your own custom URL. Works with Desktop, Mobile and Webplayer platforms (need to self-host a file in originating server for Webplayer).

More info here: http://j.mp/IRVUN

Hi,

I have released a event based plugin for ios that lets you do exactly this without having to do it manually. It is very easy to use and works on all ios devices. Android version is on works as well

I’ve created an Android’s library that can be used as Unity’s plugin for this purpose. If anyone’s interested it’s available under GitHub - rixment/awu-plugin: Android Wrapper for Unity

As for the iOS version unfortunately I don’t have enough of knowledge in this area. It would be nice if someone could extend the repo to include the iOS version too.

Cheers!