我正在构建一个基本的应用程序,其功能与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",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); }