PDF 文件未显示 ios
PDF file not showing ios
我在 firebase 服务器上有几个 pdf 文件需要在应用程序中显示给用户。
但问题是,它既不在 webview 中也不在 WKWebView 中显示 pdf 文件。
我尝试了以下代码片段,但均无效。
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 file
我也使用了 PDFKit,但也没有用。这是我尝试将其加载到 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 永远不会加载。可能是什么问题。请指导我,以便我可以解决这个问题。
使用下面的代码在WKWebView
中加载pdf
文件
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)
}
}
我在 firebase 服务器上有几个 pdf 文件需要在应用程序中显示给用户。 但问题是,它既不在 webview 中也不在 WKWebView 中显示 pdf 文件。 我尝试了以下代码片段,但均无效。
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 file
我也使用了 PDFKit,但也没有用。这是我尝试将其加载到 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 永远不会加载。可能是什么问题。请指导我,以便我可以解决这个问题。
使用下面的代码在WKWebView
pdf
文件
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)
}
}