【发布时间】:2014-10-01 22:36:44
【问题描述】:
严重缺乏关于如何在 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异常。
我曾多次问过谷歌,但它无法给出一个连贯的答案。
有人知道如何在 WP8 中使用文件插件吗?
【问题讨论】:
-
您在“严重缺乏文档”中获得了我的 +1 票 :) 只是猜测,但您是否确保授予您的应用访问文件系统的权限?
-
你的问题正好说明了我的观点!我将在哪里/如何检查或启用它?
-
我试过了,但
fileSystem.root.value是undefined。这是否仅适用于设备而不适用于模拟器?
标签: cordova windows-phone-8 cordova-plugins html5-filesystem