我一直在与AngularJS,Cordova和Ionic一起开发应用程序。过去,我一直使用Cordova文件插件将一些信息存储在设备上的文件中。
我想远离采用这种方法并删除文件。
这是我的代码段:
function migrateAwayFromDataFile() {
console.log(' migrate away from data file ');
console.log(cordova.file.dataDirectory); //file:///data/data/com.myapp.app/files/
window.requestFileSystem(cordova.file.dataDirectory, 0, function (fs) {
fs.root.getFile('filename.json', { create: false }, function (fileEntry) {
fileEntry.remove(function () {
console.log(' config file deleted ');
ErrorMessageAndDebugLogService.logDebug('Config file has been deleted successfully.');
}, function (error) {
console.log(error);
ErrorMessageAndDebugLogService.logDebugError('Could not delete Config file. ' + JSON.stringify(error));
});
});
});
}
我不断收到这些错误:
migrate away from data file
bundle.min.js:1 file:///data/data/com.myapp.app/files/
cordova.js:420 Wrong type for parameter "type" of requestFileSystem: Expected Number, but got String.
checkArgs @ cordova.js:420
cordova.js:422 Uncaught TypeError: Wrong type for parameter "type" of requestFileSystem: Expected Number, but got String.
at Object.checkArgs (cordova.js:422)
at requestFileSystem (plugins/cordova-plugin-file/www/requestFileSystem.js:50)
at bundle.min.js:1
at Object.l [as initializeApp] (bundle.min.js:1)
at bundle.min.js:1
at Array.<anonymous> (vendors.min.js:1)
at Channel.o (vendors.min.js:1)
at Channel.fire (cordova.js:840)
at cordova.js:226
为什么不起作用?
答案 0 :(得分:0)
requestFileSystem()的第一个参数必须是类型,而不是目录:
window.requestFileSystem('json'