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 to check for network connectivity

My event listener for my web view is below. I am aware that you need to have an alert for network connectivity when submitting to Apple. I am having a bit of trouble and am looking for a simple way to check for connectivity. Any suggestions?


if (e.rowData.url)
    {
      var webview =  Titanium.UI.createWebView({
            url:e.rowData.url  
      });

        win.add(webview);
        win.showNavBar();
        win.barColor = '#012F03';
    }

the whole code is below. thanks in advance
http://pastie.org/1056411

— asked July 23rd 2010 by Sean DeChellis
  • connectivity
  • iphone
  • network
0 Comments

5 Answers

  • // not online

    if (Titanium.Network.networkType == Titanium.Network.NETWORK_NONE)
    
    — answered July 23rd 2010 by Daniel Lim
    permalink
    0 Comments
  • if(!Titanium.Network.online){
         //alert user about internet
    }
    

    That's a way of checking

    — answered July 23rd 2010 by Abraham Vivas
    permalink
    1 Comment
    • This is the same check that I use.

      — commented July 23rd 2010 by Christopher Rumpf
  • i tried both of your suggestions, no luck.

    — answered July 23rd 2010 by Sean DeChellis
    permalink
    0 Comments
  • Daniel, where would I insert this code?

    In the event listener?

    — answered July 23rd 2010 by Sean DeChellis
    permalink
    1 Comment
    • Anywhere you wish, not necessary in an event listener.
      Any line on app.js, if you program requested update or download xml data lists on first use or on every app load, then use that line before doing so. Prompt error if they are not online, you can check once and halt your app from running if they are not online, the rest doesn't matter. Apple doesn't though all the checking.

      You can use that line again on webview, double check network connectivity if you wish.

      — commented July 23rd 2010 by Daniel Lim
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.