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:
Implement the
-webView:decidePolicyForNavigationAction:decisionHandler:
delegate method.Have it look for PDFs.
For non-PDFs, call the decision handler with
WKNavigationActionPolicyAllow
.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"