iOS: Check for Internet Connection?

Gerry Orkin gerry.orkin at gmail.com
Thu May 22 20:21:30 EDT 2014


There are commands for this. See the dictionary for "iphoneSetReachabilityTarget" and "reachabilityChanged. 

This is what I do. Start with this at the top of your stack script:

 global internetAvailable	

Then on openstack call this:

  iphoneSetReachabilityTarget  "google.com"

Have this in your stack script too:

on reachabilityChanged  hostNameOrAddress, reachabilityInfo
  global internetAvailable
  put reachabilityInfo into internetAvailable
end reachabilityChanged

That keeps a global variable updated with the current status of the connection. When I want to check for the current status I call this:

on internetCheck
 switch
        case internetAvailable is empty
          answer "There doesn't appear to be an internet connection. Please try again later."
          exit to top
          break
    
        case  "reachable" is among the items of internetAvailable and "is cell" is not among the items of internetAvailable  
          exit internetCheck -- there's an active wifi connection
          break
          
        case internetAvailable contains "is cell"  
          answer "There's no wifi available. Use mobile data?" With "Yes" or "No"
          if it = "Yes" then
            -- do whatever you need here
            exit internetCheck
          else
            exit internetCheck
          end if
          break
      end switch
end internetCheck



More information about the use-livecode mailing list