xcode PhoneGap 文件删除不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14962974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PhoneGap File Remove not working
提问by Megan Sime
I am building up a basic app which features PhoneGap pretty heavily as i am trying to determine what it can/can't do. i have gotten to the stage where i am looking to remove a file that has been downloaded on the app, but it won't work. most of the code i've used is from http://docs.phonegap.com/en/2.4.0/cordova_file_file.md.html#FileEntry;
我正在构建一个基本的应用程序,它以 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);
}
and i have called it using the HTML;
我用 HTML 调用了它;
<button onclick="removefile();">remove file</button>
is there something wrong with the code? i can't see it.
代码有问题吗?我看不到。
By the way I'm coding for iOS and using JavaScript, HTML and PhoneGap/Cordova in Xcode.
顺便说一下,我正在为 iOS 编码并在 Xcode 中使用 JavaScript、HTML 和 PhoneGap/Cordova。
I'm fairly new to iPhone development so any help would be great thanks a lot :)
我对 iPhone 开发还很陌生,所以任何帮助都会非常感谢:)
回答by Simon MacDonald
Your code is slightly off. Try:
你的代码有点不对劲。尝试:
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);
}
回答by Manuel Riel
Old entry. The API may have changed, but I was able to do it like this:
旧条目。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);
})