关于如何在WP8平台上使用Cordova文件插件的文档严重缺乏。WP8/Cordova文件系统 - 有谁知道正确的代码?
我有在Android,fireOS和iOS的应用程序,所有使用该文件的插件来查看目录内容,下载,保存和打开从我的web服务,所有使用下面的代码生成文件:
function listDir() {
//console.log('listDir');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
function gotFS(fileSystem) {
//console.log('gotFS. filesystem.root = ' + fileSystem.root.value);
fileSystem.root.getDirectory("MyFolder", { create: true, exclusive: false }, gotDir);
}
function gotDir(dirEntry) {
//console.log('gotDir');
// Get a directory reader
var directoryReader = dirEntry.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(success, fail);
}
function success(entries) {
var i = 0, sb = '';
sb += '<ul data-role="listview" data-inset="true" id="pdfFiles">';
if (entries.length > 0) {
for (i = 0; i < entries.length; i++) {
sb += '<li><a href="#" data-src="' + entries[i].toURL() + '"><img src="images/icons/icon_pdf.png" class="ui-li-icon" width="16px" height="16px" alt="PDF Icon" />';
sb += entries[i].name;
//sb += '<br />';
//sb += entries[i].fullPath;
sb += '</a></li>';
}
} else {
sb += '<li><p>You do not have any saved reports</p></li>';
}
sb += '</ul>';
$('#pdfReports-entries').html(sb);
$('ul#pdfFiles').listview().listview('refresh');
//open the pdf file using the fileOpener plugin
$('ul#pdfFiles li a').on('click', function() {
$this = $(this);
window.plugins.fileOpener.open($this.attr('data-src'));
});
}
function fail(error) {
logError("Failed to list directory contents: " + error.code);
sb += '<ul data-role="listview" data-inset="true" id="pdfFiles">';
sb += '<li><p>You do not have any saved reports</p></li>';
sb += '</ul>';
$('#pdfReports-entries').html(sb);
$('ul#pdfFiles').listview().listview('refresh');
}
}
WP8抛出在gotFS功能以下错误:
A first chance exception of type 'System.IO.IsolatedStorage.IsolatedStorageException' occurred in mscorlib.ni.dll
我又试图代码在this Github,仍然失败创建或读取任何目录,但不抛出IsolatedStorageException异常。
我问了很多次Google,但它无法给出一个连贯的答案。
是否任何人知道如何使用WP8文件插件?
你有我的+1投票在“有一个严重缺乏文档”:)只是一个猜测,但你确保给你的应用程序访问文件系统的权限? – CodingWithSpike 2014-10-01 22:46:28
你的问题完全说明了我的观点!我在哪里/如何检查或启用该功能? – DaveSav 2014-10-01 22:50:47
我试过这个,但'fileSystem.root.value'是'undefined'。这只能在设备上工作,而不能在仿真器上工作? – Sumit 2016-10-06 05:14:31