如何在Safari浏览器中快速打开.pdf URL

时间:2020-02-17 06:08:23

标签: swift safari

在这里,我尝试在 Safari浏览器中打开扩展名为 .pdf hosts.tmp。但是代码不起作用,我在URL中得到了零。但是,当我像“ www.google.com” 那样尝试URL时,效果很好

  • 代码

    URL

预先感谢

2 个答案:

答案 0 :(得分:-1)

尝试这个。

let cerificateURl = "https://file-examples.com/wp-content/uploads/2017/10/file-sample_150kB.pdf"

if let myURL = URL(string: url) {
    if let data = try? Data(contentsOf: myURL) {
        webView.load(data, mimeType: "application/pdf", characterEncodingName: "", baseURL: myURL
    }
}

答案 1 :(得分:-1)

尝试这个:

guard let url = URL(string: "your web pdf file link here or you can set from local directory path") 
else { return }
UIApplication.shared.open(url)