如何从WWW目录phonegap(IOS)中读取图像文件

时间:2013-04-03 00:43:13

标签: javascript ios cordova

基本上我想从phoneGap中的/ WWW / images /目录中读取/获取图像文件(jpg)以用于IOS5 / 6 但我无法访问它们。

这似乎是一项简单的任务,但我无法做到,这令人沮丧

将其编程到虚拟机中,并从模​​拟器中播放。

这是我的代码。

function first(){
    window.requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,fail1);

}
function gotFS(fileSystem){
    console.log("gotFS__");
    fileSystem.root.getFile("images/faq.jpg",null,gotFileEntry,fail1);
}
function gotFileEntry(fileEntry){
     console.log("gotFileEntry___");
    fileEntry.file(gotFile,fail1);
}
function gotFile(file){
    readDataUrl(file);
}
function readDataUrl(file){
     console.log("readDataUrl___");
    var reader =  new Filereader();
    reader.onloadend=function(evt){
        console.log("read as data URL");
        console.log("result:"+evt.target.result);


        }
    }
    reader.readAsDataURL(file);
}
function fail1(evt){
    console.log(evt.target.error.code);
}

没有错误报告。但没有任何反应 我的错在哪里? 请帮我。 最好的问候

我找到了解决方案,在我的情况下,我想打开位于www / library / pdffiles / file.pdf中的pdf文件。

   var path = window.location.pathname;
   var phoneGapPath =  path.substring(0,path.lastIndexOf('/')+1);
   var resource = phoneGapPath + "/pdffiles/"+ localFileName;
   window.plugins.childBrowser.showWebPage( resource );    

我希望如果遇到同样的问题,有人会服务。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,在我的情况下,我想打开位于www / library / pdffiles / file.pdf中的pdf文件。

var path = window.location.pathname;
var phoneGapPath =  path.substring(0,path.lastIndexOf('/')+1);
var resource = phoneGapPath + "/pdffiles/"+ localFileName;
window.plugins.childBrowser.showWebPage( resource );   

我希望如果遇到同样的问题,有人会服务。