- Home /
Detect if device is connected to Wifi
Hello,
I am developing an app for mobile and need to be able to tell if the device is connected to the internet via WIFI or via 3G. I have already managed to do so for the android version, using a pulgin that exposes native calls, but I can't seem to find any solution for iOS. Does somebody have any suggestions or plugins that can help me solve this issue?
Thanks in advance, ConfusedExpert
Answer by CodeElemental · Jun 29, 2016 at 08:13 AM
Can you try this approach out ? http://stackoverflow.com/questions/24351155/unity-check-internet-connection-availability
This approach works for checking if the device is connected to the internet. What I would like to know is if the device is connected using WIFI, or not.
Are you sure? From what i can read in the unity documentation it should work.
http://docs.unity3d.com/ScriptReference/NetworkReachability.ReachableViaLocalAreaNetwork.html
Forgive me, your solution works perfectly. Thanks a lot CodinRonin!
Answer by ntsparmar · Jun 29, 2016 at 05:29 PM
check this condition its working for me
if(Network.player.ipAddress!="0.0.0.0"){ //your are Connected in Network }
Very nice idea, I used this and this one works the best, but it will only work on mobile with 100% stability.
Because on PC if you insert a LAN cable and then pull it out then it reserves your IP address, so it will return true even when you are not connected to Lan nor Wifi.
Answer by ankitdave · Jun 30, 2016 at 05:15 PM
@ConfusedExpert void Start() { string url = "http://google.com"; WWWForm form = new WWWForm(); WWW www = new WWW(url);
if (www.error == null)
{
//means wifi or mobile data is on
//do whatever you want here like suppose
Application.LoadLevel("login scene");
}
else
{
//means wifi or mobile data is off,
//now do whatever you want to do.
}
}
That only tells them if they are connected to the internet not whether it is a WiFi or 3G connection.