使用cordova插件删除iOS中应用程序的临时目录
delete temp directory of an app in iOS using cordova plugin
我使用ionic框架在iOS的Library目录中的应用程序中存储一些图像。是否可以使用Cordova插件文件和Cordova插入文件传输删除相同的目录?
有人能帮忙吗?
我下载图像的代码是:
downloadImage: function(url, fileName) {
var deferred = $q.defer();
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
fs.root.getDirectory(
LOCAL_STORAGE_KEYS.app, {
create: true
},
function(dirEntry) {
// console.log(arguments);
dirEntry.getFile(
fileName, {
create: true,
exclusive: false
},
function(fe) {
console.log(arguments);
var p = fe.toURL();
console.log("In service the url path:", p);
fe.remove();
var ft = new FileTransfer();
console.log('File Transfer instance:', ft);
ft.download(
encodeURI(url),
p,
function(entry) {
console.log('In service the entry callback:', entry);
if (entry && entry.toURL) {
deferred.resolve(entry.toURL());
} else {
console.log('No entry:', arguments);
deferred.resolve();
}
},
function(err) {
console.log('Getting rejected:', err);
deferred.reject(err);
},
false,
null
);
},
function() {
deferred.reject(new Error('get file failed'));
}
);
}
);
},
function() {
deferred.reject(new Error('get directory failed'));
});
return deferred.promise;
}
以下是使用cordova文件插件删除目录及其内容的示例代码片段:
function clearDirectory() {
if (ionic.Platform.isAndroid()) {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemDirSuccess, fail);
} else {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemDirSuccess, fail);
}
function onFileSystemDirSuccess(fileSystem) {
var entry = "";
if (ionic.Platform.isAndroid()) {
entry = fileSystem;
} else {
entry = fileSystem.root;
}
entry.getDirectory("DIRECTORY_TO_DELETE", {
create: true,
exclusive: false
},
function(entry) {
entry.removeRecursively(function() {
console.log("Remove Recursively Succeeded");
}, fail);
}, getDirFail);
}
function getDirFail(error) {
navigator.notification.alert("Error");
};
function fail(error) {
navigator.notification.alert("Error");
};
}
相关文章:
- 在cordova android应用程序中连接数据库
- 无法在基于Cordova的应用程序中读取Set Cookie标头
- 如何将tesseract OCR与Cordova/Phonegap应用程序集成
- AngularJs Cordova安卓应用程序中输入的4位密码PIN验证
- 当我在重新启动cordova应用程序后尝试添加更多数据时,lokijs会丢失数据库和收集中的数据
- 从Cordova应用程序中的Azure AD获取access_token
- iOS Cordova应用程序-shouldStartLoadWithRequest
- 无法在Windows 10 Cordova应用程序中从Web视图进行ajax调用
- Cordova包装应用程序内部链接加载在应用程序中,外部链接加载在浏览器中
- 如何使用Quickblox在Cordova应用程序中实现推送通知支持
- 无法在iOS模拟器上运行简单的基于KineticJs的Cordova/PhoneGap应用程序
- 如何使用onDeviceReady设置AngularJS应用程序并初始化Cordova的功能
- 在移动设备上按路径或名称获取二进制图像(Ionic / Ng cordova 应用程序)
- 在ios Cordova应用程序中打开iTunes窗口
- 带有Apache Cordova的Android应用程序
- Apache Cordova:在不启动浏览器应用程序的情况下运行Cordova运行浏览器
- 我想在混合移动应用程序中使用Sqlite插件(Cordova)创建一个示例项目
- cordova.exec() 正在破坏我的应用程序代码
- Cordova的Firebase/Phonegap:使用应用程序内的电子邮件/密码登录
- 如何在我的移动应用程序(cordova)上启用跨域资源共享,它连接到API(在Yii中)