PDF文件不显示ios [英] PDF file not showing ios
本文介绍了PDF文件不显示ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 firebase 服务器上有几个 pdf 文件,我需要在应用程序中向用户显示.但问题是,它既没有在 webview 中也没有在 WKWebView 中显示 pdf 文件.我尝试了以下代码片段,但都没有奏效.
I have few pdf files at firebase server that i need to show to the users in the app. But the problem is, it doesn't show the pdf files neither in webview nor in WKWebView. I tried the following code snippets but neither worked.
if let url = URL(string: urlString){
// First Approach
if let data = try? Data(contentsOf: url) {
webView.load(data, mimeType: "application/pdf", characterEncodingName: "", baseURL: url)
}
// Second Approach
let req = URLRequest(url: url)
self.webView.load(req)
}
这是其中一个网址.PDF 文件
我也使用了 PDFKit,但这也不起作用.这是我尝试将其加载到 webview 时的日志.
I used the PDFKit as well but that also didn't work. Here is the log when i try to load it into webview.
2020-05-21 21:06:01.561593+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
2020-05-21 21:06:10.383853+0500 Mini Muslims[41242:748632] WF: _userSettingsForUser : (null)
2020-05-21 21:06:10.384063+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
2020-05-21 21:06:13.050745+0500 Mini Muslims[41242:748634] Task <5CBC8251-89EC-4DCD-A9A0-E794B3AEB6EC>.<0> HTTP load failed, 0/0 bytes (error code: -999 [1:89])
2020-05-21 21:06:18.123494+0500 Mini Muslims[41242:748632] WF: _userSettingsForUser : (null)
2020-05-21 21:06:18.123672+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
2020-05-21 21:06:18.173099+0500 Mini Muslims[41242:748632] WF: _userSettingsForUser : (null)
2020-05-21 21:06:18.173315+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
2020-05-21 21:06:19.260676+0500 Mini Muslims[41242:748632] WF: _userSettingsForUser : (null)
2020-05-21 21:06:19.260878+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
2020-05-21 21:06:22.607212+0500 Mini Muslims[41242:748632] WF: _userSettingsForUser : (null)
2020-05-21 21:06:22.607351+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
2020-05-21 21:06:23.080709+0500 Mini Muslims[41242:748632] WF: _userSettingsForUser : (null)
2020-05-21 21:06:23.080916+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
2020-05-21 21:06:28.736644+0500 Mini Muslims[41242:748632] WF: _userSettingsForUser : (null)
2020-05-21 21:06:28.736875+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
2020-05-21 21:06:36.769000+0500 Mini Muslims[41242:748632] WF: _userSettingsForUser : (null)
2020-05-21 21:06:36.769220+0500 Mini Muslims[41242:748632] WF: _WebFilterIsActive returning: NO
pdf 永远不会加载.可能的问题是什么.请指导我,以便我解决此问题.
The pdf never loads. What could be the possible issue. Please guide me so that i can resolve this issue.
推荐答案
使用下面的代码加载WKWebView
import UIKit
import WebKit
class ViewController: UIViewController,UIWebViewDelegate,UIScrollViewDelegate, WKUIDelegate {
var WKwebView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let userContentController: WKUserContentController = WKUserContentController()
let conf = WKWebViewConfiguration()
conf.userContentController = userContentController
WKwebView = WKWebView (frame: CGRect( x: 0, y: 60, width: self.view.frame.width, height: self.view.frame.height - 60 ), configuration: WKWebViewConfiguration())
WKwebView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
WKwebView.uiDelegate = self
WKwebView.scrollView.bounces = false
WKwebView.scrollView.delegate = self;
view.addSubview(WKwebView)
var request : URLRequest!
let PDFURL = "https://firebasestorage.googleapis.com/v0/b/mini-muslims.appspot.com/o/Books%2F-M5HgblfIM4jvINka3j2?alt=media&token=745ca3e3-b18b-4b2a-96c1-e791f977c2df";
let url : URL = URL(string: PDFURL as String)!
request = URLRequest (url: url);
WKwebView.load(request)
}
}
这篇关于PDF文件不显示ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文