iOS Question Simple Ping or Network check

tufanv

Expert
Licensed User
Longtime 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
 

Derek Johnson

Active Member
Licensed User
Longtime User
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime 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.
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime 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.

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.
 
Upvote 0

sorex

Expert
Licensed User
Longtime 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
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime 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

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:
Upvote 0

sorex

Expert
Licensed User
Longtime 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:
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime 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.

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.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Will do for a & b

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

Derek Johnson

Active Member
Licensed User
Longtime User
c can't be avoided I'm affraid unless you login first with safari or some other browser.

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

I know that there are arguments for and against using ping as a method of verifying internet connectivity

and I simply want to get on and try out alternative methods.
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime 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.
 
Upvote 0
Top