Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Checking for network connectivity

I am using the code below in an attempt to notify users that they are not connected to a network. The problem is, my alertDialog box doesn't show up in the simulator when I test my app with no internet connectivity. Is there something missing from my code? I am using it in app.js

Full Code: http://pastie.org/1066272


// check for network
if(!Titanium.Network.networkType == Titanium.Network.NETWORK_NONE){
     var alertDialog = Titanium.UI.createAlertDialog({
              title: 'WARNING!',
              message: 'Your device is not online.',
              buttonNames: ['OK']
            });
            alertDialog.show();
}
— asked July 29th 2010 by Sean DeChellis
  • alert
  • connectivity
  • dialog
  • iphone
  • network
0 Comments

8 Answers

  • Accepted Answer

    You got it backward
    if(Titanium.Network.networkType == Titanium.Network.NETWORK_NONE){
    // that's no network connectivity.
    }

    if(Titanium.Network.networkType != Titanium.Network.NETWORK_NONE){
    anything but no connectivity
    }

    — answered July 29th 2010 by Daniel Lim
    permalink
    0 Comments
  • I use this:

    function check_network() {
        return Titanium.Network.online;
    }
    

    and works even in simulator ( I cut the airport )

    — answered July 29th 2010 by Dan Tamas
    permalink
    1 Comment
    • And how to cut airport mode in the simulator?

      — commented February 17th 2014 by Gustavo Severo
  • I've always just loaded it onto my device and went in airport mode after the sync.

    I'd love to know if it's possible in the simulator.

    — answered July 29th 2010 by Riley Hamilton
    permalink
    0 Comments
  • Actually now it is showing the alertDialog when I am connected to a network.

    Any suggestions?

    — answered July 29th 2010 by Sean DeChellis
    permalink
    0 Comments
  • Tamas, I replaced your code with mine.

    I am not getting an alert pop-up with your code, should I be seeing an alert that tells me I am not connected to a network? Thanks

    — answered July 29th 2010 by Sean DeChellis
    permalink
    0 Comments
  • Tamas, I replaced your code with mine.

    I am not getting an alert pop-up with your code, should I be seeing an alert that tells me I am not connected to a network? Thanks

    — answered July 29th 2010 by Sean DeChellis
    permalink
    0 Comments
  • Thanks Daniel, I found the fix with your solution.

    
    // check for network
    if(Titanium.Network.networkType == Titanium.Network.NETWORK_NONE){
         var alertDialog = Titanium.UI.createAlertDialog({
                  title: 'WARNING!',
                  message: 'Your device is not online.',
                  buttonNames: ['OK']
                });
                alertDialog.show();
    }
    
    — answered July 29th 2010 by Sean DeChellis
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.