1

我在科爾多瓦的文件插件有一個奇怪的問題。下面的代碼工作正常,如果我運行它爲Windows Phone 8.1應用程序。但它沒有,如果我運行它作爲Windows Phone的通用應用程序科爾多瓦文件閱讀器不工作

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
     function (fs) { 
      fs.root.getFile("www/test.xml", null, function (fileEntry) { 
       fileEntry.file(gotFile, fail); 
      }, fail); 
     }, fail); 

錯誤回調函數被調用,錯誤代碼1.這意味着

function (fs) { 
      fs.root.getFile("www/test.xml", null, function (fileEntry) { 
       fileEntry.file(gotFile, fail); 
      }, fail); 

呼叫後,該文件是不找到。有沒有人有一個想法是什麼問題?如果是這樣,我該如何解決它。

我想,我在錯誤的文件系統。有誰知道我必須使用?

我知道有一些類似的問題,但它們只涉及windows phone 8.1而不涉及windows phone universal。 我在Visual Studio中使用cordova。

回答

0

我無法像windows phone 8.1應用那樣工作。

{create:true}使用如下代碼試了一下:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
    function (fs) { 
     fs.root.getFile("test.xml", { create: true }, function (fileEntry) { 
      fileEntry.file(gotFile, fail); 
     }, fail); 
}, fail); 

,我得到了fileEntry象下面這樣: enter image description here

正如你可以看到新創建的文件的nativeURLms-appdata:///local//test.xml,這意味着它不是在應用程序目錄下創建的,但是在如下的C:\Users\<username>\AppData\Local\Packages\<application identity name>\LocalState下:

enter image description here

我研究了文檔,但沒有找到檢索應用程序目錄文件的方法。 所以目前的解決辦法是使用Windows API來獲取應用程序目錄下的文件象下面這樣:

if (cordova.platformId == "windows") 
{ 
    var uri = new Windows.Foundation.Uri("ms-appx:///www/test.xml"); 
    Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (fs) { 
       var abc = fs;//get the file here 
      },fail); 
} 
+0

謝謝,這個解決方案正常工作。 – BenHeid