6

I'm trying to open a PDF I have stored on the device. The files open in the Xcode Simulator, but not on an iPhone.

These are the things I know:

  • The files are there, I can see them with contentsOfDirectory
  • I can open web pages using the same code, if they are http links, but not if they are https links
  • I can also open pdf files from the web, if they are in https links, but not when they are http

Is this a security problem of some kind? What can I do? Thanks!

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)
        }
Riku Virta
  • 103
  • 1
  • 5
  • 2
    This was actually answered here: https://stackoverflow.com/questions/24882834/wkwebview-not-loading-local-files-under-ios-8 – Riku Virta Jan 27 '18 at 20:32

0 Answers0