Web View PDF download

How to make a page downloadable as pdf in ios web view as i am using download pdf code in ASP.net MVC but when i try to download it in ios web view it just simply shows the page but the page cannot be downloaded.

Replies

I’m assuming you’re using

WKWebView
here. If you’re using one of our deprecated web views, there are equivalent techniques available but, rather than go into details, my recommendation is that you switch to
WKWebView
first.

The standard way of implementing downloads in a web view is:

  1. Implement the

    -webView:decidePolicyForNavigationAction:decisionHandler:
    delegate method.
  2. Have it look for PDFs.

  3. For non-PDFs, call the decision handler with

    WKNavigationActionPolicyAllow
    .
  4. For PDFs, call the decision handler with

    WKNavigationActionPolicyCancel
    and start the download via other means. For example, you might use an
    NSURLSession
    background session to guarantee that the download continues even if your app is moved to the background.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"