Search Unity

Application.internetReachability is bugged ?

Discussion in 'Scripting' started by Liszt, Apr 29, 2015.

  1. Liszt

    Liszt

    Joined:
    Jan 12, 2015
    Posts:
    29
    Hi,
    if a Unity developer is in the neighbourhood an explanation could be nice.

    I use this "Application.internetReachability" in a switch case to determine if my user get the internet.

    If I start my apps without internet connection the result is good and the enum value return is
    "NetworkReachability.NotReachable".
    During the game, the player switch on the WiFi and the value return is the good one : "NetworkReachability.ReachableViaLocalAreaNetwork" but if you switch off the WiFi after this the value stay lock on "NetworkReachability.ReachableViaLocalAreaNetwork" whereas there is no more connections.

    I use this on Android build with a Sony Xperia Z3 Compact if this can help you to give me more hints on this problem.

    Thanks in advance guys.
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    I'm going to quote the documentation found here:
    http://docs.unity3d.com/ScriptReference/Application-internetReachability.html

    What I made bold first and foremost states that you should NOT use this property to determine if you're connected to the internet.

    The rest of it implies what this really is doing. It basically determines that there is hardware available to connect to a network.

    The comment about non-handhelds always being considered connectable means that we can infer that this thing really only performs any hardware tests on handhelds. What's probably going on is if wifi is off when you start the application, the test fails, so it returns not reachable. But once you turn on the wifi, the test returns true, hardware validity is confirmed, and therefore always returns true... the application knows hardware exists since it existed at some point. No point in testing again!
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    If you want to determine if you're actually on the internet you can always just attempt to make a connection with some known web-server that is always on. Like google for instance...
     
  4. Liszt

    Liszt

    Joined:
    Jan 12, 2015
    Posts:
    29
    Yeah I read the documentation it's just the way to do that is weird for me. Why don't set it to "true" if a Wifi module is detected ?! It could be set to true before switch on the wifi.

    I try to do 2 things first I test the internetReachability and then if a "ReachableViaLocalAreaNetwork" is detected then I try to ping an IP address. But for me it's not a good idea. I try to find something more accurate.
     
  5. Aram-Azhari

    Aram-Azhari

    Joined:
    Nov 18, 2009
    Posts:
    142
    I have the same problem. Once the value is set to true, it is never set to false again. How is this not a bug?