How to open a Link to a PDF with wkwebview

2019-04-14 23:12发布

I created a simple iOS App, which opens a URL with WKWebView. Into website the site, there is a link to a PDF Document. When I open the site into my browser, I can click onto the Link, and the PDF document opens. But into my App, nothing happens, when I click onto the link. How can I fix it? Do I have to put something into my info.plist?

Thanks for help.

1条回答
来,给爷笑一个
2楼-- · 2019-04-14 23:51

SWIFT 3.* & 4.* *

First you have to download that pdf file into your app, after downloading you have to get that file path, then that file path should be use like following way in WKWebView.

let fileURL = URL(fileURLWithPath: filePathURLData as! String)
//print(fileURL)
webView.loadFileURL(fileURL, allowingReadAccessTo: fileURL)

Here filePathURLData is your actual file path which you have downloaded into your app, you have to convert this into URL, then you need to load that file into WKWebView

Thanks

Hope this will help you.

This will show any file in the WKWebView (doc, docx, xlsx, pdf, google doc, pages & Any textfile)

查看更多
登录 后发表回答