0

I have a Swift application that opens a PDF file in webView with the function webView.load(request).

It perfectly works at debug time with the simulator, but when launched in the real device (an iPad) the PDF file is not shown.

The app does not set any error.

Any help is welcome

3 Answers3

0

This might be so obvious question: Is your iPad connected to internet?

Then maybe it's because your link isn't and "https://...." but just an "http://" and maybe the webview won't open it because of that

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Leo
  • 68
  • 9
  • The PDF file is located in the default documents folder. Any loading to the webView is working, but not the loading of a PDF file. The strange is that the same code works in the simulator. – Giuseppe Biondo Aug 23 '17 at 12:24
  • Oh ok I thought you were using a url, so yes your problem is very strange in this case... Can I see the code you are using ? – Leo Aug 23 '17 at 12:32
  • https://stackoverflow.com/questions/29682245/how-to-load-local-pdf-in-uiwebview-in-swift/29682393 Check this out , I think using the way "sketchyTech" may solve your problem – Leo Aug 23 '17 at 12:47
  • @IBAction func showPdf(_ sender: Any) { let req = NSURLRequest(url: getPathOfPdfFile()) webView.load(req as URLRequest) } // in the simulator it works – Giuseppe Biondo Aug 23 '17 at 12:49
  • The problem seems caused by the wrong setting of the subView. By adding a subView the problem disappears. how to manage correctly this and way in the simulator is not necessary to add the subview ? – Giuseppe Biondo Aug 23 '17 at 16:34
0

The PDF file is located in the default documents folder. Any loading to the webView is working, but not the loading of a PDF file. The strange is that the same code works in the simulator.

  • Exact same problem. webView.load(urlRequest) works perfectly on simulator (12.0) ; but on iPad (11.4) I just get the view that contains the web view plus a button in this view. But the webView does not load. Code is straightforward: let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] let filePath = "\(documentsPath)/\(filename).pdf" let url = NSURL(fileURLWithPath: filePath) let urlRequest = URLRequest(url: url as URL) webView.load(urlRequest) On iPad, url shows as url file:///var/mobile/Containers – claude31 Aug 22 '18 at 19:47
0

For Swift 3 use this

let url = URL(fileURLWithPath: filePath)
let urlRequest = URLRequest(url: url)
webView?.loadRequest(urlRequest)
AkBombe
  • 638
  • 4
  • 10