Titanium Community Questions & Answer Archive

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

Simple code example to check if there is a network conncection

Hi there,

is there someone who can expand this two lines of code with a check if there is a network connection an give out a warning if not?

Here is my simple example:

btn_03_01.addEventListener('click', function()
    {
        Titanium.Platform.openURL('www.appcelerator.com');
    });

thank you!

— asked May 11th 2010 by Bruno Mandolesi
  • check
  • connection
  • connectivity
  • network
0 Comments

2 Answers

  • Accepted Answer

    try this:

    btn_03_01.addEventListener('click', function()
        {
            if(Ti.Network.online){
                Titanium.Platform.openURL('www.appcelerator.com');
            } else {
                var alertDialog = Titanium.UI.createAlertDialog({
                  title: 'WARNING!',
                  message: 'Your device is not online.',
                  buttonNames: ['OK']
                });
                alertDialog.show();
            }
        });
    
    — answered May 11th 2010 by Clint Tredway
    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.