本文介绍了是否可以在SFSafariViewController上加载本地pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用WKWebViewController,但仍然无法正常工作.
I tried with WKWebViewController, but still not working.
url = [[NSBundle mainBundle] URLForResource:@"manual_eos_1d_x" withExtension:@"pdf"];
WKWebViewController * controllerweb = (WKWebViewController *)[segue destinationViewController];
controllerweb.url = url;
推荐答案
无法在SFSafariViewController中显示本地pdf,但可以在WKWebView中显示它. SFSafariViewController仅支持http和https方案.
It is not possible to show local pdf in SFSafariViewController, but it is possible to display it in a WKWebView. SFSafariViewController only support http and https schemes.
从SFSafariViewController init(url :)文档:
From SFSafariViewController init(url:) documentation:
要在WKWebView中显示本地pdf文件,您可以执行类似于以下代码的操作:
To show local pdf file in WKWebView, you can do something similar to the following code:
let mainBundle:Bundle = Bundle(for: WKWebContainerView.self)
let path = mainBundle.path(forResource: "sample", ofType: "pdf")
let pdfUrl = URL(fileURLWithPath: path!)
let folderUrl = URL(fileURLWithPath: mainBundle.bundlePath, isDirectory: true)
webView.loadFileURL(pdfUrl, allowingReadAccessTo: folderUrl)
这篇关于是否可以在SFSafariViewController上加载本地pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!