有人可以向我解释这里发生了什么吗?下面的代码在Android上运行得非常好,但在黑莓10上无效。
对于数组中的前两个目录结构,我没有看到调用parentDir.getDirectory(),但是在“parentFolder”文件夹中成功创建了数组中的最后一个路径(“dir / 3 / dir6”)在blackberry.io.home文件夹中。
var dirList;
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
alert("device ready");
blackberry.io.sandbox = false;
dirList = ["dir1/dir4/", "dir2/dir5/", "dir3/dir6/"];
getFileSystem();
}
function getFileSystem(){
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem)
{
console.log("Success getting filesystem !!!");
createDirectoryRecursive(fileSystem);
},
function(error){
console.log("Failed to get the filesystem !!!!!");
}
);
}
function createDirectoryRecursive(fs){
var i;
for(i = 0; i < dirList.length; i++){
createDirs(fs.root, dirList[i], -1);
}
}
function createDirs(parentDir, filePath, index)
{
console.log("createDirs params ===> parentDir=" + parentDir.toURL() + " filePath=" + filePath + " index=" + index);
var arrDirs = filePath.split("/");
console.log("number of levels in path = " + arrDirs.length);
if (index >= (arrDirs.length - 1))
{
console.log("Done with " + filePath);
}
else{
var dirName = "parentFolder";
if (index >= 0)
{
dirName = arrDirs[index];
console.log("current dirName is " + dirName);
}
//if device is Blackberry, build up a full directory path as we are trying to install outside of sandbox
var path, dirToCreate = ""
if(device.platform == "blackberry10"){
path = "parentFolder/";
console.log("Paths ======> arrDirs = " + arrDirs + " index = " +index);
for (i = 0; i <= index; i++){
path += arrDirs[i] + "/";
console.log("path = " + path + " i = " + i + " index = " + index);
}
dirToCreate = blackberry.io.home + "/" + path;
dirToCreate = dirToCreate.substring(0, dirToCreate.length - 1);
console.log("Paths Trying to create " + dirToCreate);
dirName = dirToCreate;
}
parentDir.getDirectory(dirName, {create: true, exclusive: false},
function (directoryEntry) {
console.log("getDirectory callback =======> created directory " + directoryEntry.fullPath);
console.log("getDirectory callback =======> Current arrdirs " + arrDirs);
createDirs(directoryEntry, filePath, index + 1);
},
function (error) {console.log("Failed to get directory " + dirName + " Error code : " + error.code);});
}
}
代码实际上为数组中的所有目录输入了cordova的DirectoryEntry.getDirectory函数,但是没有调用回调(成功或失败)。只在黑莓设备上处理并创建列表中的最后一个目录路径。
答案 0 :(得分:0)
我一直面临同样的问题。值得你试试这个,
window.webkitRequestFileSystem(window.PERSISTENT, 5*1024*1024, onSuccess, null);
而不是:
window.requestFileSystem(LocalFileSystem.PERSISTENT,5 * 1024 * 1024,onSuccess,null);
你的getFileSystem()中的。
当我挖掘并找到此文档时,我获得了更多信息:https://bbjam.blackberryconferences.net/asia2013/connect/fileDownload/session/52C12DB41EDB8F70FDF15253F02948B7/JAM847_BBJamAsia-JAM847.pdf
希望它适用于所有人。