Page 1 of 1

Checking Internet Connection

Posted: Sat Aug 25, 2012 6:40 pm
by endernafi
Hi there dear LiveCoders,

At some certain occasions, my apps crash if there is no internet connection.
Here is my solution to check if there is connection.

Put a blank text file on a server, your website or any other secure location.
In my case, the file is only 13bytes.
Then put this code snippet into your script:

Code: Select all

function checkInternetConnection
  if the environment is "mobile" then
     put "http://www.example.com/checkConnection.txt" into theSource
     put specialFolderPath("documents") & "/checkConnection.txt" into theTarget
     libUrlDownloadToFile theSource, theTarget
     if ((there is a file theTarget) and (calcFileSize(specialFolderPath("documents"), "checkConnection.txt") > 0)) then
        delete file theTarget
        return true
     else
        return false
     end if
  else
     return false
  end if
end checkInternetConnection
Then,

Code: Select all

if checkInternetConnection() then
   -- do your stuff here
end if
Is there a better, faster or more secure way to check internet connection on iPhone?
Please, share your ideas.


Regards,

~ Ender Nafi Elekcioglu

Re: Checking Internet Connection

Posted: Sat Aug 25, 2012 8:23 pm
by Dixie
Hi...

Look at page 53 of the 'iOS Release notes'... and read up on 'Network Reliability Checking'. I've used quite a lot, it says that it is experimental, but it works well.

be well

Dixie

Re: Checking Internet Connection

Posted: Sun Aug 26, 2012 2:08 am
by FireWorx
What version of Livecode IOS release notes? I checked page 53 and didn't see anything about it. Searched under "Network Reliability Checking" and it returned empty.
Dave

Re: Checking Internet Connection

Posted: Sun Aug 26, 2012 3:52 am
by Dixie
Dave..

LiveCode 5.5.1.... but I did make a mistake, I should have written 'Network reachability' not 'Network reliability'... I did check the release notes again, Page 53 it is...

be well

Dixie

Re: Checking Internet Connection

Posted: Sun Aug 26, 2012 9:48 am
by endernafi
Thanks Dixie,

I'm reading that section, now.
Actually I'll read whole iOS release notes once again from start.
Obviously, one can miss things out.

Thanks again,

Regards,

~ Ender Nafi Elekcioglu

Re: Checking Internet Connection

Posted: Sat Mar 09, 2013 7:18 am
by FireWorx
Hey Dixie,
If you have it working can you supply some sample code. It's a little confusing to me.
Thanks,
Dave

Re: Checking Internet Connection

Posted: Sat Mar 09, 2013 8:23 am
by Simon
Hi Dave,
Before you need your internet connection just put:
iphoneSetReachabilityTarget "http://www.whatever.com" (Well make it meaningful to the site you are reading from).

Then use:
on reachabilityChanged "http://www.whatever.com", tReach
switch tReach
case = "transient"
--do something
break
--and so on
end reachabilityChanged
to monitor that you are still connected.

Simon

Re: Checking Internet Connection

Posted: Sat Mar 09, 2013 9:00 pm
by FireWorx
Cool. This worked for me to let me know if internet was available.
on mouseup
CheckTheNet
end mouseup

in the stack the scripts below were inserted

on CheckTheNet
put "http://www.myserver.on-rev.com" into tMyServer
iphoneSetReachabilityTarget tMyServer, reachabilityChanged
end CheckTheNet

on reachabilityChanged tMyServer, tReach
if "connection required" is among the items of tReach then answer "Internet connection required"
if tReach is "reachable" then answer "The server is accessible"
end reachabilityChanged

Re: Checking Internet Connection

Posted: Thu Mar 14, 2013 4:59 am
by FireWorx
Well perhaps not so cool ! It stopped working with the following error.

stack "Untitled 1": execution error at line 40 (Handler: can't find handler) near "iPhoneSetReachabilityTarget", char 1

Oh well I guess they say its experimental. Worked fine the other day! go figure

Re: Checking Internet Connection

Posted: Thu Mar 14, 2013 5:10 am
by Simon
hmmmm... that reads like an error from the IDE.
You should have
if the environment is "mobile" then
CheckTheNet

Simon

Re: Checking Internet Connection

Posted: Thu Mar 14, 2013 5:22 am
by FireWorx
Ha ha ha.... Yes thanks Simon! I wasn't working in the simulator! I was on my desktop! Silly Me!
Thank You