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