PDA

View Full Version : detecting network connection in sencha



fgeorge
21 Dec 2010, 11:46 AM
Hello,
Ii want to create an app which will first check if there is a connection to the internet.

If there is, then pull the latest information via a JSON feed..if not pull up data from localstorage..

how can i do this with sencha touch?

thanks

jeffremer
21 Dec 2010, 12:10 PM
Sencha Touch doesn't provide any extra functionality around this AFAIK, but it's a pretty simple new javascript API per the HTML5 spec.



// This property is true if you are online, false if not
window.navigator.onLine


Of course you'll need to do some extra work like spec'ing a cache-manifest to have whatever local assets you need available offline in the first place (aside from local storage for the data you want to display).

mrsunshine
21 Dec 2010, 12:17 PM
afaik there is no api for it in st where you can check network.online?
but you can make the normal request and on failure callback (no network) you load the data from the local store