built-in check for internet connection

It would be really nice to have a built-in function that checks to see if the user’s device is currently connected to the internet. That way we don’t have to use a time-out function and get to keep full functionality in case the user’s internet is extraordinarily slow.

Thanks,
Matt
W2MD [import]uid: 10211 topic_id: 9555 reply_id: 309555[/import]

its on the daily build

[code]
function MyNetworkReachabilityListener(event)
print( “address”, event.address )
print( “isReachable”, event.isReachable )
print(“isConnectionRequired”, event.isConnectionRequired)
print(“isConnectionOnDemand”, event.isConnectionOnDemand)
print(“IsInteractionRequired”, event.isInteractionRequired)
print(“IsReachableViaCellular”, event.isReachableViaCellular)
print(“IsReachableViaWiFi”, event.isReachableViaWiFi)

–[[ If you want to remove the listener, call network.setStatusListener(“www.apple.com”, nil)
g_Counter = g_Counter + 1
if g_Counter > 3 then
print(“removing event listener”)
– event:removeEventListener()
network.setStatusListener( “www.apple.com”, nil)
end
–]]

end

if network.canDetectNetworkStatusChanges then
network.setStatusListener( “www.apple.com”, MyNetworkReachabilityListener )
else
print(“network reachability not supported on this platform”)
end
Test whether this Reachability instance is of interest.
If so, then test what kind of network transition it is:
Is the host reachable? isReachable;
Is the connection up? isConnectionRequired;
Will it come up automatically? isConnectionOnDemand;
Will the user have to enter a password? isInteractionRequired;
Is the connection slow? isReachableViaCellular;
Is the connection fast? isReachableViaWiFi;

[/code] [import]uid: 24 topic_id: 9555 reply_id: 34894[/import]

check for

event.isReachable [import]uid: 24 topic_id: 9555 reply_id: 34895[/import]

Hello guys.

My upcoming app (MAD GODS) has been reject by Apple. Even so they did not specifically said why (“app freeze when pressing the run button”) I am suspecting something about the way I am checking for network connection before requesting an ad from Playhaven network. On my device (ios) I can see that if I enable the “network link conditioner” (settings/developer/network…) I can see that the app freezes at start if the I simulate a bad network connection (100% or 70% data loss) I think the this network status simulation only works on ios 7. Anyway I have been using in the past something like this:

[lua]

   function testNetworkConnection()

        local netConn = require(‘socket’).connect(‘www.apple.com’, 80)

        if netConn == nil then

            return false

        end

        netConn:close()

        return true

    end          

           

   [/lua]

I have seen many variation of the above code which seems to not really prevent my Playhaven to be called if there is a bad connection. I have tried codes with network time out but got basically the same issue.

THEN, i found the above post about build-in function for checking internet connection! Of course i did not about that. Still I am having problem implementing since it was always return “false” for some reason!

inside that function (MyNetworkReachabilityListener) he I added the following:

netOK = event.isReachable    – netOK is local variable define above the function and use to show or not a Playhaven ad

My problem is that netOK flag is always false?  Is that the way to check if the device is connected to the internet (ie: get the status of isReachable?) 

Also in the post above (from Carlos) I do not see how/where “network” is define? Should not have something like:

local network = requires (“socket”)  

or something like that? or is it something like:

local network = requires (“network”) ???

2 more questions!:

1- Does the build-in internet connection work both on IOS and android? if not what will be a better solution to check for internet connection on both OS?

2- Is there anyway to tell how good/bad the internet connection is? In my case if the connection is good then everything is ok BUT if i simulate a bad connection then the app really behave badly!

THANK YOU! I am really desperate to fix this issue so i can re-submit my app to Apple and see what they say!

Mo

Hello guys.

My upcoming app (MAD GODS) has been reject by Apple. Even so they did not specifically said why (“app freeze when pressing the run button”) I am suspecting something about the way I am checking for network connection before requesting an ad from Playhaven network. On my device (ios) I can see that if I enable the “network link conditioner” (settings/developer/network…) I can see that the app freezes at start if the I simulate a bad network connection (100% or 70% data loss) I think the this network status simulation only works on ios 7. Anyway I have been using in the past something like this:

[lua]

   function testNetworkConnection()

        local netConn = require(‘socket’).connect(‘www.apple.com’, 80)

        if netConn == nil then

            return false

        end

        netConn:close()

        return true

    end          

           

   [/lua]

I have seen many variation of the above code which seems to not really prevent my Playhaven to be called if there is a bad connection. I have tried codes with network time out but got basically the same issue.

THEN, i found the above post about build-in function for checking internet connection! Of course i did not about that. Still I am having problem implementing since it was always return “false” for some reason!

inside that function (MyNetworkReachabilityListener) he I added the following:

netOK = event.isReachable    – netOK is local variable define above the function and use to show or not a Playhaven ad

My problem is that netOK flag is always false?  Is that the way to check if the device is connected to the internet (ie: get the status of isReachable?) 

Also in the post above (from Carlos) I do not see how/where “network” is define? Should not have something like:

local network = requires (“socket”)  

or something like that? or is it something like:

local network = requires (“network”) ???

2 more questions!:

1- Does the build-in internet connection work both on IOS and android? if not what will be a better solution to check for internet connection on both OS?

2- Is there anyway to tell how good/bad the internet connection is? In my case if the connection is good then everything is ok BUT if i simulate a bad connection then the app really behave badly!

THANK YOU! I am really desperate to fix this issue so i can re-submit my app to Apple and see what they say!

Mo