Wifi Detect Question

Ok,
I have this at the top of my main.lua file

[lua]local 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)
end
if network.canDetectNetworkStatusChanges then
network.setStatusListener( “www.mywebsite.com”, MyNetworkReachabilityListener )
else
print(“network reachability not supported on this platform”)
end[/lua]
then I have a button that is going to call a function to load a webPopup. I want to make sure that before the webpopup shows that I have established that Wifi is on… if it isn’t then I want to just leave the screen as is and send an alert saying connect to wifi etc.

This is what I have that doesn’t work.

[lua]local function showVideos (event)
if event.phase == “release” then
media.playEventSound( “Tock.caf” )
if event.isReachableViaWiFi == “false” then
local alert = native.showAlert(“No Wifi Detected”, “Please connect and try again”, {“OK”})
else

mainScreen:slideToLeft( videosScreen )
buttons.isVisible = false
options2 = { hasBackground=false}
native.showWebPopup(0,42,320,400, “http://www.mywebsite.com/videos.php”, options2)
bottomBar.isVisible = true
back.isVisible = true

end
end
videosScreen:addBackButton(goBack2)
end

local button2 = ui.newButton{
default = “buttonRed.png”,
over = “buttonRedOver.png”,
text = “Videos”,
onEvent = showVideos,
emboss = true
}[/lua]

Any help would be greatly appreciated. I am sure I am missing something real simple.

Matt [import]uid: 18783 topic_id: 11054 reply_id: 311054[/import]

@mattchapman,
your code does not work because

  1. you haven’t called the reachability function anywhere

  2. event.isReachableViaWiFi is available in the event object when the myNetowkrReachabilityListener is called, the showVideos is called via the Button from ui.newButton so the events object will not have the isReachableViaWiFi==“false”

I hope that is good enough a point to start from,

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 11054 reply_id: 40257[/import]

I follow you. I placed the entire function inside the showVideos event even and although the console correctly shows

isReachable true
isConnectionRequired false
isConnectionOnDemand false
IsInteractionRequired false
IsReachableViaCellular false
IsReachableViaWiFi true

when the button is pressed I can’t get the if statement to pickup the result and act on it.

I think I need coffee.
Matt
[import]uid: 18783 topic_id: 11054 reply_id: 40260[/import]

Syntax syntax syntax! Good lord I had isReachableViaWifi not isReachableViaWiFi. the F is caps now all is better…

[import]uid: 18783 topic_id: 11054 reply_id: 40278[/import]