PhoneGap文件删除不起作用

PhoneGap File Remove not working

本文关键字:不起作用 删除 文件 PhoneGap      更新时间:2023-09-26

我正在构建一个基本的应用程序,该应用程序非常重视PhoneGap,因为我正在努力确定它能做什么/不能做什么。我已经到了想要删除应用程序上下载的文件的阶段,但它不起作用。我使用的大部分代码来自http://docs.phonegap.com/en/2.4.0/cordova_file_file.md.html#FileEntry;

    function removefile(){
        fileSystem.root.getFile("readme.txt", {create: false, exclusive: false}, gotRemoveFileEntry, fail);
    }
    function gotRemoveFileEntry(fileEntry){
        console.log(fileEntry);
        fileEntry.file(gotFile, fail);
        entry.remove(success, fail);
    }
    function success(entry) {
        console.log("Removal succeeded");
    }
    function fail(error) {
        console.log("Error removing file: " + error.code);
    }

我用HTML来命名它;

    <button onclick="removefile();">remove file</button>

代码有问题吗?我看不见。

顺便说一句,我正在为iOS编码,并在Xcode中使用JavaScript、HTML和PhoneGap/Cordova。

我是iPhone开发的新手,所以任何帮助都会很棒,非常感谢:)

您的代码有点偏离。尝试:

function removefile(){
    fileSystem.root.getFile("readme.txt", {create: false, exclusive: false}, gotRemoveFileEntry, fail);
}
function gotRemoveFileEntry(fileEntry){
    console.log(fileEntry);
    fileEntry.remove(success, fail);
}
function success(entry) {
    console.log("Removal succeeded");
}
function fail(error) {
    console.log("Error removing file: " + error.code);
}

旧条目。API可能已经改变了,但我可以这样做:

function success(entry) {
  console.log("Removal succeeded");
}
function fail(error) {
  console.log("Error removing file: " + error.code);
}
resolveLocalFileSystemURL(cordova.file.dataDirectory + 'assets/icons/test.png', function(entry) {
  console.log(entry);
  entry.remove(success, fail);
})