Checking for wifi / 3g

Is there a way to do a check to check whether the user has an internet connection at the start of an app?

thanks. [import]uid: 5708 topic_id: 747 reply_id: 300747[/import]

not at this moment. will add as feature…

C. [import]uid: 24 topic_id: 747 reply_id: 1527[/import]

I check the connection in this way (see “Network support for the Lua language”):

local http = require(“socket.http”)
local ltn12 = require(“ltn12”)

function check_conn()
answer={} – This contains text web page (or other output from server), if it found
local error=“Network OK”

local wawurl=“http://www.google.com” – or other site, of course
local c,r=http.request{
url = wawurl,
sink = ltn12.sink.table(answer)
}
if r==“host not found” then
error=r
end
if (r~=200 and r~=“host not found”) then
error="HTTP error "…r
end
return error
end

At the moment I found this problem: if the Corona application is the first one to search for connectivity, the previous “check connection function” gives always back an error.
If it is not the first application to search for Internet and “check connection” gives back an error, this is true.
bye
[import]uid: 2735 topic_id: 747 reply_id: 1579[/import]

We’re aware of that limitation and working on a fix. [import]uid: 54 topic_id: 747 reply_id: 1626[/import]

Till the fix is here, the workaround that pmaxim posted is great. Works like a charm. [import]uid: 5712 topic_id: 747 reply_id: 1628[/import]

Is there any official Ansca update on this? Thank you! [import]uid: 4621 topic_id: 747 reply_id: 4937[/import]

Here’s what works for me. I show a dialog / alert to the user when they open the app if they don’t have a net connection (test with airplane mode), and then they are forced to exit the app.

[lua]--------------------------------------------------------
– Verify Net Connection

local http = require(“socket.http”)
local ltn12 = require(“ltn12”)

if http.request( “http://www.google.com” ) == nil then

local function onCloseApp( event )
if “clicked” == event.action then
os.exit()
end
end

native.showAlert( “Alert”, “An internet connection is required to use this application.”, { “Exit” }, onCloseApp )
end[/lua] [import]uid: 4621 topic_id: 747 reply_id: 4938[/import]