Cordova iOS直接下载pdf

时间:2018-02-12 09:02:07

标签: ios cordova pdf download

我尝试使用命令

直接从网络应用下载pdf
window.open(target, '_blank', 'location=no');

在Android中,它的效果非常好,但在iOS中它只显示PDF的预览,只有" DONE"按钮,没有任何"下载"或"打开"动作按钮。

有没有办法处理它?我读过一些东西,却找不到任何东西......

由于

1 个答案:

答案 0 :(得分:1)

iOS与Android不同,它无法下载文件。

您的选择是:

在Safari中打开,这样它就会显示出来,并且会打开"打开"允许您在另一个应用程序中打开它的选项。 要在safari中打开,请使用此代码window.open(target, '_system');

在您的应用内下载。 您必须在这里选择,使用XHR调用或使用cordova-plugin-file-transfer 对于XHR,请参阅此答案的示例 Download binary data into the app sandbox using XHR2 request instead of cordova-file-transfer

对于文件传输,请参阅此示例代码:

// !! Assumes variable fileURL contains a valid URL to a path on the device,
//    for example, cdvfile://localhost/persistent/path/to/downloads/

var fileTransfer = new FileTransfer();
var uri = encodeURI("http://some.server.com/yourFile.pdf");

fileTransfer.download(
    uri,
    fileURL,
    function(entry) {
        console.log("download complete: " + entry.toURL());
    },
    function(error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("download error code" + error.code);
    },
    false,
    {}
);
相关问题