Phonegap使用File-Transfer在iOS中下载文件并在设备中访问它

时间:2015-07-21 14:48:48

标签: ios cordova file-transfer

我使用Phonegap和jQuery Mobile创建了一个应用程序,它在iPad mini中工作得很好,而且我正在使用File-Transfer在设备中下载文件,日志说该文件已成功下载但我不能在设备的任何地方找到pdf文档,这是我的代码:

function iosDownload() { 
    var fileTransfer = new FileTransfer(); 
    var uri = encodeURI("WEB_SERVICE_URL"); 

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) { 
        var fileNamePath = fs.root.fullPath + "/file.pdf"; 
        fileTransfer.download( uri, fileNamePath, function(entry) { 
            console.log("download complete: " + entry.fullPath); 
            alert("Reporte generado exitosamente"); 
            }, function(error) { 
                console.log("download error source " + error.source); 
                console.log("download error target " + error.target); 
                console.log("upload error code" + error.code); 
                alert("Error al generar reporte. Intentar mas tarde"); 
            }, false, { 
                headers: { 
                    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" 
                } 
            } 
        ); 
    }); 
} 

日志中的响应显示了此路径:

下载完成:/var/mobile/Containers/Data/Application/DEVICE_UNIQUEID/Documents/file.pdf

我找不到该文档,有没有办法在Downloads文件夹中下载它?或者有没有办法在那个地方找到它?感谢。

1 个答案:

答案 0 :(得分:1)

查看此文件路径

Users/YourAccount/Library/Developer/CoreSimulator/Devices/45BCFA0B-C37A-4A85-A63C-(device's ID)/data/Containers/Data/Application/E4472D7E-A833-4985-89CF-(App's ID)/Documents/yourfile.pdf

希望有所帮助。 你保存的路径相同。

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) { 
    var fileNamePath = fs.root.fullPath + "/file.pdf"; 
    $scope.fileToShow = fileNamePath;

}

HTML

<div>fileToShow</div>

如果您想在iPad上看到自己的PDF格式,请安装iExplorer

iExplorer

连接iPad并打开iExplorer。然后转到文件和应用程序,并选择您的应用程序。您的pdf将在Documents。