03-29-2011 09:37 PM
Is there a known way to check for an internet connection? My app uses an external web service to load data into my app. If on wifi everything works great...but if there is no wifi or internet connection, it just fails. Is there a way to test for a connection? I'm concerned this will be used against me in the app approval process. Any help would be greatly appreciated.
03-29-2011 10:38 PM - edited 03-29-2011 10:39 PM
How about URLMonitor and SocketMonitor? You can find out more here:
http://www.davidtucker.net/2007/12/15/air-tip-1-%E
03-30-2011 01:05 AM
I had that same issue. Here's how I did it. This will even tell you what your IP is.
Imports:
import flash.events.Event; import flash.events.IOErrorEvent; import flash.net.Socket;
Socket Sonnection:
var socket:Socket = new Socket();
socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
socket.addEventListener(Event.CONNECT, socketConnect);
socket.connect("google.com", 80);
Connection Events:
private function socketConnect(event:Event):void
{
ip = event.target.localAddress;
connected = true;
}
private function socketError(error:IOErrorEvent):void
{
trace(error.text);
}