2013-11-22 44 views
0

有人可以向我解釋這裏發生了什麼?下面的代碼在Android上運行得非常好,但在黑莓10上不起作用。使用cordova2.9和webworks在blackberry10上遞歸創建目錄路徑

對於數組中的前兩個目錄結構,我沒有看到調用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);}); 

    } 
} 

的代碼實際上確實進入科爾多瓦的DirectoryEntry.getDirectory功能的陣列中的所有目錄,但沒有回調(成功或失敗)被調用。只有列表中的最後一個目錄路徑才能在黑莓設備上成功處理和創建。

回答

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

希望它適用於每一個人。