我正在尝试打开存储在设备上的PDF。这些文件在Xcode Simulator中打开,但不在iPhone上打开。
这些是我所知道的:
这是某种安全问题吗?我能做什么?谢谢!
let documentDirectory = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
var pdfToOpen: URL!
var fileName = "fileName.pdf"
override func viewDidLoad() {
super.viewDidLoad()
pdfToOpen = documentDirectory.appendingPathComponent(fileName)
openPDF(pdfToOpen)
}
func openPdf(input: URL?) {
if let url = input {
let webView = WKWebView(frame: CGRect(x: 0, y: 20, width: self.view.frame.width, height: self.view.frame.height-20))
let urlRequest = URLRequest(url: url)
webView.load(urlRequest as URLRequest)
self.view.addSubview(webView)
}