Ariel Gemilang Ariel Gemilang - 7 months ago 36
Swift Question

cannot view pdf to web view using file path

i have an app to download pdf file. If the download completed it have a path like


I try to view using this

@IBOutlet weak var webView: UIWebView!

var path = ""
var receiveData: String = "" //this contain file:///Users/developer.../Caches/pdffile.pdf

override func viewDidLoad() {
let url = NSURL.fileURLWithPath(receiveData)
self.webView.loadRequest(NSURLRequest(URL: url))

the build succeded and no error butstill can't view the pdf file

what's wrong?


Change your NSURL path, you need to use receiveData, because that already contain the path of the file, NSBundle is use when you have file inside your project directory.

 let url = NSURL.fileURLWithPath(receiveData)