Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appcache in Cordova app

I'm developping a mobile app using Cordova (3.4). My core application files are embedded in my app archive (.apk or .ipa), and some files (js/html/css) must be retrieved from my server. So if I want my application usable offline I need to use appcache for these files.

A sample of my appcache.manifest :

CACHE MANIFEST
# version 7


NETWORK:
*
http://*
https://*

CACHE:
# Message module
http://my.server.ip/module/routes.json
http://my.server.ip/module/css/style.css
http://my.server.ip/module/js/controller.js
http://my.server.ip/module/js/service.js
...

My index.html (embedded into my app) :

<!DOCTYPE html>
<html lang="en" xmlns:ng="http://angularjs.org" id="ng-app" ng-app="app" 
                          manifest="http://my.server.ip/tmp_appcache.manifest">
...
<body>
<script>
    document.addEventListener("deviceready", function(e) {
        var appCache = window.applicationCache;

        alert('device ready');

        console.log('appCache', appCache);
        // Fired after the first cache of the manifest.
        appCache.addEventListener('cached', function(event) {
            console.log(event);
            alert('Appcache OK');
        }, false);

        appCache.addEventListener('UpdateReady', function(event) {
            console.log(event);
            alert('Appcache Reloaded');
        }, false);


        appCache.addEventListener('error', function(event) {
            console.log(event);
            alert('Appcache ERROR');
        }, false);

        appCache.addEventListener('checking', function(event) {
            console.log(event);
            alert('Appcache CHECKING');
        }, false);

        appCache.addEventListener('downloading', function(event) {
            console.log(event);
            alert('Appcache DOWNLOADING');
        }, false);

        appCache.addEventListener('noupdate', function(event) {
            console.log(event);
            alert('Appcache NOUPDATE');
        }, false);

        appCache.addEventListener('obsolete', function(event) {
            console.log(event);
            alert('Appcache OBSOLETE');
        }, false);
    }, false);
</body>
</html>

My problem is, when I launch my pp (on Android AND iOS), I didn't see any of my alert (except the "device ready"), and no file is cached.

If I open the url of my webapp in the device browser I actually see my alert.

Is there an additional configuration to do in Phonegap to allow appcache ?

I've seen some article about enabling appcache in Android, but it seems to be for older version of cordova, furthermore it doesn't work for me and if it's the origin of my problem, appcache should work on iOS.

Any idea would be helpful. Thanks

like image 712
Tako Avatar asked Mar 25 '14 10:03

Tako


Video Answer


1 Answers

AppCache is not supported in Cordova 3.4 and up to 4.0 and no plans for support that standard in the near future (as of 17/Apr/2015).

like image 149
codevision Avatar answered Oct 18 '22 04:10

codevision