JayVDiyk
JayVDiyk

Reputation: 4487

View Downloaded PDF on UIWebView

I have managed to download pdf file to the device.

I get this file:///var/mobile/Containers/Data/Application/DBC9AFAB-3FD4-4D06-82F5-0577251001A7/Library/Caches/RewardMe-Presentation-at-NVIDIA-Auditorium.pdf path

So I tried to open it on an UIWebView like this

    let downloadedFilePath = "file:///var/mobile/Containers/Data/Application/DBC9AFAB-3FD4-4D06-82F5-0577251001A7/Library/Caches/RewardMe-Presentation-at-NVIDIA-Auditorium.pdf"
    let filePathURL = NSURL(fileURLWithPath: downloadedFilePath);
    webView.loadRequest(NSURLRequest(URL: url));

But the WebView fails to load the pdf. It only shows a blank webview

Any ideas why this does not work?

Upvotes: 0

Views: 1093

Answers (1)

Abdul Rehman
Abdul Rehman

Reputation: 2456

You code looks ok but the path is not

 let downloadedFilePath = "///var/mobile/Containers/Data/Application/DBC9AFAB-3FD4-4D06-82F5-0577251001A7/Library/Caches/RewardMe-Presentation-at-NVIDIA-Auditorium.pdf"
        let filePathURL = NSURL(fileURLWithPath: downloadedFilePath);
        webView.loadRequest(NSURLRequest(URL: url));

Try this hope it works.

For checking that the file exist Open a new finder and press Command+Shift+G after that copy and paste the file path and press enter If the file load then the file exist. File path in your case is " ///var/mobile/Containers/Data/Application/DBC9AFAB-3FD4-4D06-82F5-0577251001A7/Library/Caches/RewardMe-Presentation-at-NVIDIA-Auditorium.pdf "

Upvotes: 1

Related Questions