【问题标题】:Cordova or phonegap : saving file catcherCordova 或 phonegap :保存文件捕捉器
【发布时间】:2016-01-25 08:39:16
【问题描述】:


我目前用 javascript 开发了一个应用程序,我想使用 cordova 或 phonegap 来使我的代码适应 android、Iphone 等。但是在我的应用程序中,我使用这个函数保存了我的文件:

function save(){
    var myFileJSON = JSON.stringify(myFile);
    try{
        var blob = new Blob([myFileJSON], {type: "text/plain;charset=utf-8"});
        saveAs(blob, "myFileJSON.txt");
    } catch (e){
        console.log('bug');
    }
}

因此,我想通过我的手机应用程序将我的文件保存在特定文件夹中。我可以捕获保存事件并立即重定向路径吗?

【问题讨论】:

    标签: javascript android ios cordova


    【解决方案1】:
    function saveCourseToFile() {
       console.log("checkpoint 1");
       window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, onFSError);
    }
    function onFSSuccess(fileSystem) {
       console.log("checkpoint 2");
       console.log("Opened file system: " + fileSystem.name);
       fileSystem.root.getFile("readme.txt", {create:true, exclusive:false}, gotFileEntry, onFSError);
    }
    function gotFileEntry(fileEntry) {
       console.log("checkpoint 3");
       fileEntry.createWriter(gotFileWriter, onFSError);
    }
    function gotFileWriter(writer) {
       writer.onwrite = function(evt) {
          console.log("checkpoint 4: write success!");
       };
       writer.write("test test test");
    }
    

    您也可以查看this 链接以供参考。

    【讨论】:

    • 所以当我用我的 js 调用 save 时,手机应用程序中的这个函数会将它保存在我想要的位置?
    • 保存的文件将在根文件夹中可用。如果有用,请采纳答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    相关资源
    最近更新 更多