how do you alert users?

You must Login before you can answer or comment on any questions.

I want to alert users if the webview that I have tried to fire within the app doesn't have internet connection or to notify the user if the page doesn't load. Any thoughts? Thanks for your help in advance!

Code:

var label = Titanium.UI.createLabel({

backgroundImage: "images/google.png",
top: 0,
width: "100%",
height: "12%",
textalign: "center",

})

// new button

var openWebpagenotification = Titanium.UI.createButton({ title:"google", backgroundImage: "images/notificationbutton.png", width:"100%", height:"12%", top:"10%", id: "google", url:"http://www.google.com",

});

openWebpagenotification.addEventListener("click", function(e){

// Create a window and add a webview to it that opens your url: var webviewWindow = Titanium.UI.createWindow({title: 'google', fullscreen: false});
var myWebView = Ti.UI.createWebView({url:e.source.url}); webviewWindow.add(myWebView);

// Will need a button to close the new window: var closeButton = Titanium.UI.createButton({title:'Close', style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN}); webviewWindow.setLeftNavButton(closeButton);

closeButton.addEventListener('click',function(evt){ webviewWindow.close(); });

webviewWindow.open({modal:true}); webviewWindow.open(); // Open your new window })

2 Answers

Hi Paul

You could (and should) check against this boolean Ti.Network.online. You should check this property before using any views that require an internet connection and before firing any network APIs using HTTPClient.

You use it like this;

if (Titanium.Network.getOnline === true( {
    // then show your web view
} else {
    // show a friendly label on the window instead letting them know.
}
More information can be found in the Ti.Network - online method documentation.

Keep in mind that you should check the status again, so if content is not shown on a modal dialog, consider using an eventlistener to determine any changes with the network and then take appropriate action.

Titanium.Network.addEventListener('change', function (e) {
    if (e.online === true) {
        // same logic
    } else {
        // as above
    }
});
More information can be found in the Ti.Network - Change Event documentation.

— answered 10 months ago by Malcolm Hollingsworth
answer permalink
3 Comments
  • Did this solve your problem?

    — commented 10 months ago by Malcolm Hollingsworth

  • I haven't tried it yet. my wife just delievered our newborn. so I have been so busy with that. I am going to try and look at it this upcoming weekend. Thank you again for your help. I will keep you posted on it - I don't quite understand it reading it here but I will read up on this. Thanks again!

    — commented 10 months ago by paul wamser

  • Congratulations, ready when you are - Daddy :)

    — commented 10 months ago by Malcolm Hollingsworth

Your Answer

Think you can help? Login to answer this question!