iOS Question Simple Ping or Network check

Discussion in 'iOS Questions' started by tufanv, Jul 23, 2015.

  1. tufanv

    tufanv Expert Licensed User

    Hello

    As we dont have the game center lib , I will have to use a server to store all the players scores. But if the user does not have an internet connection i will skip the score upload step. So how can i basicly check if the user is connected to internet. I wanted to use inetwork and getmyip method and check if the ip is other than 127.0.0.1 but sometimes the ip address is 192.168.x.x for example and also there is no internet connection. So what is the simplest way to check if the user is connected to internet ?

    TY
     
  2. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    The best way it to send a http request to your server and see whether it is accessible or not.
     
  4. Derek Johnson

    Derek Johnson Active Member Licensed User

    Last edited: Sep 21, 2015
  5. sorex

    sorex Expert Licensed User

    a ping doesn't tell anything.

    the reply could come from the router/firewall and not the webserver itself so the webserver might not respone at all.

    so the only safe method is actually calling a page of your backend.
     
  6. Derek Johnson

    Derek Johnson Active Member Licensed User

    Yes I know that. The scenario that I am using is different from what you describe however. I'm wanting to check if access to a website that my app may not have visited before is likely to succeed. It is not my server.

    One case I want to address is where the user is using my app while mobile and may need to log in to a wifi hotspot before the connection will succeed.
     
  7. sorex

    sorex Expert Licensed User

    a page fetch will do then. you can work with job.success status and check for a keyword in the job.response text to be sure that the request was 100% successful
     
  8. Derek Johnson

    Derek Johnson Active Member Licensed User

    You seem to be of the opinion that it would be better for the user to wait 15 secs for the response to time out, rather than to do a 1 second check on basic connectivity beforehand.

    OK thats your opinion, now can anyone help me with what I requested in the first place.

    Thanks
     
    Last edited: Sep 21, 2015
  9. sorex

    sorex Expert Licensed User

    maybe you should first try it out before making conclusions?

    if the site is down it will just take a bit longer as a ping and just report an error.

    Edit: tested this on Android and it's instant error reporting, will need to test this on IOS when I get home.
     
    Last edited: Sep 21, 2015
  10. Derek Johnson

    Derek Johnson Active Member Licensed User

    Ok and maybe you should report back when

    (a) You are using an iPhone/iPad rather than an Android device

    (b) When you are attempting to connect to page with https://

    (c) When you walk up to a HotSpot that has supposedly open access but then requests that a login that must be completed using http protocol.
    Personally I have tried out your suggestions before I posted my request.
     
  11. sorex

    sorex Expert Licensed User

    Will do for a & b

    c can't be avoided I'm affraid unless you login first with safari or some other browser.
     
  12. Derek Johnson

    Derek Johnson Active Member Licensed User

    Now that's the usage case I'm trying to address. In some cases this results in simply no response at all, and an extended timeout.

    I did say at the very beginning of this query

    and I simply want to get on and try out alternative methods.
     
  13. Derek Johnson

    Derek Johnson Active Member Licensed User

    A quick way to force the timeout issue, when working from home - disconnect your router from the internet, but do not switch it off.

    Result: You have a WiFi address but no connectivity - takes 30 sec plus to time out using a standard http request.
     
Loading...