[Resolved] Detecting network presence

Hi all, just a quick question…
What is the quickest/easiest way of detecting the presence of a data network (3G/WiFi etc) ?
I’ve used apps in the past that have tried to access a network service (such as game centre) and it just slows things down when there is no access. What I’d like in my app is to check for network availability before trying to access things like gamecentre or facebook.

Cheers
Chris
[import]uid: 7841 topic_id: 31792 reply_id: 331792[/import]

Hey Chris,

This should help you out:

http://docs.coronalabs.com/api/event/networkStatus/isReachable.html

You can also check the other API’s under ‘network status’ to do additional checks for cellular and wifi networks. [import]uid: 62706 topic_id: 31792 reply_id: 126909[/import]

Try something like suggested here: http://sree.cc/corona-sdk/verifying-internet-connection-in-corona-sdk

That should do the trick :slight_smile: [import]uid: 52491 topic_id: 31792 reply_id: 126913[/import]

I think the network status checks are iOS only. For simplicity

  
local socket = require "socket"  
  
local function testNetworkConnection()  
 local netConn = socket.connect('www.google.com', 80)  
 if netConn == nil then  
 return false  
 end  
 netConn:close()  
 return true  
end  

That won’t tell you if you’re on WiFi or Cellular data like the networkStatus will, but …

[import]uid: 19626 topic_id: 31792 reply_id: 126919[/import]

Excellent! As always, this place rocks :slight_smile:
Cheers guys! [import]uid: 7841 topic_id: 31792 reply_id: 126925[/import]

Hey Chris,

This should help you out:

http://docs.coronalabs.com/api/event/networkStatus/isReachable.html

You can also check the other API’s under ‘network status’ to do additional checks for cellular and wifi networks. [import]uid: 62706 topic_id: 31792 reply_id: 126909[/import]

Try something like suggested here: http://sree.cc/corona-sdk/verifying-internet-connection-in-corona-sdk

That should do the trick :slight_smile: [import]uid: 52491 topic_id: 31792 reply_id: 126913[/import]

I think the network status checks are iOS only. For simplicity

  
local socket = require "socket"  
  
local function testNetworkConnection()  
 local netConn = socket.connect('www.google.com', 80)  
 if netConn == nil then  
 return false  
 end  
 netConn:close()  
 return true  
end  

That won’t tell you if you’re on WiFi or Cellular data like the networkStatus will, but …

[import]uid: 19626 topic_id: 31792 reply_id: 126919[/import]

Excellent! As always, this place rocks :slight_smile:
Cheers guys! [import]uid: 7841 topic_id: 31792 reply_id: 126925[/import]