Question

I'm developing an web HTML5 application for the iPhone and I'm stuck at a rather wierd situation. I need to cache the whole thing for offline usage and that's fine, but the thing is, when you are online later it still uses the cache version. I need the app to use the online version instead of the cached version when it can, but I don't manage to find any info on doing that.

Thanks in advance!

Was it helpful?

Solution

I don't know what framework you are using, but in Sencha, you need to specify to use the network by doing something like this:

NETWORK:
*

If you have things in your manifest file, it will always use that cached copy, which is what you are experiencing. So that is the default behavior for items that are in your manifest file.

Now, it gets a little trickier.

Article: http://www.sencha.com/learn/taking-sencha-touch-apps-offline/

In this Sencha offline example, they set a proxy for cached database, and then switch between the browser cache and the local storage.

Then, you want to create a listener without a timeout to detect if you are offline or online.

If you timeout, then use the local proxy. Like this:

this.onlineStore.addListener('load', function () {
    console.log("I think we are online");
    helloWorld.offlineStore.proxy.clear();
    this.each(function (record) {
        var photo = helloWorld.offlineStore.add(record.data)[0];
    });
    helloWorld.offlineStore.sync();
    helloWorld.gallery.bindStore(helloWorld.offlineStore);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top