在BlackBerry应用程序中缓存

时间:2014-08-11 14:08:55

标签: cordova blackberry-10 blackberry-webworks

我已经实施了一系列缓存数据的方法,但它似乎无法在BlackBerry中运行(在Android和iOS中运行正常)。

我正在使用Cordova FileSystem API和WebWorks进行调试 有谁知道如何解决这个问题?

保存缓存:

saveCache: function(fileName, data, writeEnd, onFail){// Takes Two parameters ;the fileName that will be generated and its content (JSON format : Adapter Result)
            if (typeof LocalFileSystem != 'undefined') {

                window.requestFileSystem(LocalFileSystem.TEMPORARY, 1024 * 1024, gotFS, fail);//Invoking Cordova's FileSystem

                function gotFS(fileSystem) {
                    fileSystem.root.getFile(fileName, {create: true}, gotFileEntry, fail);//Creating Cache File named fileName
                    function gotFileEntry(fileEntry) {
                        fileEntry.createWriter(gotFileWriter, fail);//Calling the fileWriter , if Success it writes the data into the file, If failure calls fail method to display the error
                    }
                    function gotFileWriter(writer) {
                        writer.onwriteend = function(evt) {
                            console.log("Write Ended");
                            writeEnd();
                        };


                           writer.write(Base64.encode(data));// Writing data  


                    }
                }

从缓存中加载

loadCache: function(filename, loadEnd, onFail){
            if (typeof LocalFileSystem != 'undefined') {

window.requestFileSystem(LocalFileSystem.TEMPORARY, 1024 * 1024, gotFS, fail);

                function gotFS(fileSystem) {
                    fileSystem.root.getFile(filename, { create: false }, gotFileEntry, fail);
                    function gotFileEntry(fileEntry) {
                        fileEntry.file(gotFile, fail);
                    }
                    function gotFile(file){
                        readAsText(file);
                    }
                    function readAsText(file) {
                        var reader = new FileReader();

                        reader.onloadend = function(evt) {
                            console.log("Read as text");
                            //console.log(Base64.decode(evt.target.result));   
                            alert(evt.target.result);
                            loadEnd(Base64.decode(evt.target.result));
                        };
                        reader.readAsText(file);

                    }
                }
                function fail(evt) {
                    console.log(evt.target.error.code);
                    onFail();
                }
            }else{
                onFail();
            }
        },

0 个答案:

没有答案