如何使用wkwebview打开指向PDF的链接 [英] How to open a Link to a PDF with wkwebview

查看:671
本文介绍了如何使用wkwebview打开指向PDF的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的iOS应用,该应用使用WKWebView打开URL.在网站上,有指向PDF文档的链接.在浏览器中打开站点时,可以单击链接,然后打开PDF文档.但是在我的应用程序上,当我单击链接时没有任何反应.

I created a simple iOS app, which opens a URL with WKWebView. On the website, there is a link to a PDF Document. When I open the site on my browser, I can click onto the Link, and the PDF document opens. But on my App, nothing happens when I click onto the link.

我该如何解决?我是否需要在我的 info.plist 中放入一些内容?

How can I fix it? Do I have to put something into my info.plist?

推荐答案

SWIFT 3. *& 4. * *

首先,您必须将pdf文件下载到您的应用中,下载后,您必须获取该文件路径,然后应按照WKWebView中的以下方式使用该文件路径.

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)

这里filePathURLData是您已下载到应用程序中的实际文件路径,您必须将其转换为URL,然后需要将该文件加载到WKWebView

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

谢谢

希望这会对您有所帮助.

Hope this will help you.

这将显示WKWebView中的任何文件(doc,docx,xl​​sx,pdf,google doc,页面和任何文本文件)

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

这篇关于如何使用wkwebview打开指向PDF的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆