有人能向我解释一下这里发生了什么吗?下面的代码在安卓系统上运行得很好,但在黑莓10上不起作用。
对于数组中的前两个目录结构,我没有看到parentDir.getDirectory()被调用,但是数组中的最后一个路径("dir/3/dir6")是在blackberry.io.home文件夹中的"parentFolder"文件夹中成功创建的。
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函数,但没有调用回调(成功或失败)。只有列表中的最后一个目录路径在黑莓设备上被成功处理和创建。
我一直面临着同样的问题。值得你尝试一下,
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
希望它对每个人都有效。