Titanium Community Questions & Answer Archive

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

Network detection on the iPhone

Hi people

I may be being a bit thick but is there a way you can determine if the iPhone has a signal or is wirelessly connected.

I am running the HTTPclient to obtain a list of tweets and using the normal get(), onload(), send() methods. My main concern was if someone trys to run it with no signal or wireless conecttion is there a method that would achieve this.


— asked August 27th 2010 by Steve Clark
  • http
  • iphone
  • js

4 Answers

  • Simple way, with an AlertDialog popup:

    var network = Titanium.Network;
    if (network.online == false) {
        Ti.UI.createAlertDialog({title:'No Cellular Data Network', message:'Please connect to a cellular data network.', buttonNames:['Close']}).show();
    — answered August 27th 2010 by Colton Arabsky
  • Hii,

    Im sure theres a better way of doing it.. But the only function ive found so far checks wether there is a network connection or not. You could be connected to WIFI but have no internet connection, or on 3G but have run out of credit so cannot access the web but it will still let you know theres a network connection (Well.. Thats because there is! Would be cool if there was a check to see wether it can connect to the web).. Anyway, i use the below! As you can see i use xhr.onload and xhr.onerror

        xhr.send({ugcImage:imageUpload, ugcAudio:audioUpload, ugcName:nameTextField.value, 
    ugcEmail:emailTextField.value, ugcMessage:messageTextArea.value,ugcLatitude:latitude, 
    ugcLongitude:longitude, ugcAccuracy:accuracy, ugcStation:station});
       var sendingDialog = Titanium.UI.createAlertDialog({
               message: 'Sending message…'
        xhr.onload = function xhrSuccess(){
            var responseText = xhr.responseText;
            if(responseText == "true") {
                alert("Message has been sucesfully sent.");
                sent = true;
                sendBtn.title = 'Message Sent';
            } else {
                alert("Message was unsuccessful in sending. Please try again.");
                sent = false;    
        xhr.onerror = function xhrError(){
            alert("Message was unsuccessful in sending. Please try again.");
            sent = false;    
    — answered August 27th 2010 by Scott Robinson
  • The right way to do it is:

    if (  Titanium.Network.online ) {
     // do ur stuff
    else {
    alert( "This application requires internet connection.")

    This is what Apple recommends and if you fail to warn the user that needs internet for some functions will reject your app.

    — answered August 27th 2010 by Dan Tamas
    1 Comment
    • Tamas,
      I need to check if my send to server was successful and I wanted to handle a button enabled/disabled. which is at the end of my app. Reading your post, Im thinking there should be a warning on loading the app. Is that what apple wants? I need to know as much detail for apple rejecting and app as possible bc we need to get the app up and running asap!

      Could you get back to me please?

      — commented December 10th 2010 by Wade Smith
  • Titanium.Network.online

    — answered August 28th 2010 by Peter Lum
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.