38807

WKWebView save pdf to ibooks, save pdf from link

I'm Junior and currently working on project where Im in WKWebView and there are links to open pdf. I can open it in Safari and then open in iBooks, but i want it to do it inside my app. Is it possible ?

Here are pics how it looks like:

picture where i can select pdf

<img src=https://www.e-learn.cn/content/wangluowenzhang/"https://i.stack.imgur.com/ZNcPU.png" alt="description1">

picture what it will open

<img src=https://www.e-learn.cn/content/wangluowenzhang/"https://i.stack.imgur.com/2yJLi.png" alt="description2"> my webview class

class WebVC: UIViewController, WKUIDelegate { var webView: WKWebView! override func viewDidLoad() { super.viewDidLoad() let myURL = NSURL(string: "\(savedURL!)") let myRequest = URLRequest(url: myURL! as URL) webView.load(myRequest) webView.allowsBackForwardNavigationGestures = true webView.allowsLinkPreview = false } override func viewWillAppear(_ animated: Bool) { self.navigationController?.toolbar.isHidden = false } override func loadView() { let webConfiguration = WKWebViewConfiguration() webView = WKWebView(frame: CGRect(x: 100, y: 100, width: 110, height: 110), configuration: webConfiguration) webView.uiDelegate = self view = webView } @IBAction func logoutPressed(_ sender: AnyObject) { defaults.set(false, forKey: "isLogged") defaults.set("EMPTY URL", forKey: "savedURL") _ = self.navigationController?.popToRootViewController(animated: true) } @IBAction func goBack(_ sender: Any?) { if (self.webView.canGoBack) { self.webView.goBack() } } }

Answer1:

I solved it with UIDocumentInteractionController, add a button and when I push the button It will download whole page and then present DocumentController where "import to iBooks" option is. Hope it helps.

@IBAction func shareBtn(_ sender: AnyObject) { var localPath: NSURL? Alamofire.download(webView.url!, method: .get, parameters: nil, headers: nil) { (tempUrl, response) in let directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] let pathComponent = response.suggestedFilename localPath = directoryURL.appendingPathComponent(pathComponent!) as NSURL? return (destinationURL: localPath as! URL, options: .removePreviousFile) }.response { response in if localPath != nil{ self.docController = UIDocumentInteractionController(url: localPath! as URL) self.docController.presentOptionsMenu(from: sender as! UIBarButtonItem, animated: true) } } }

Recommend

  • How can I fix impaired functionality caused by disallowed useragent?
  • Installing Flash Player on an Android Emulator
  • Convert row values into columns in R
  • How to link a work load item with a commited change?
  • Is Lambda code repeated with dynamically created controls?
  • How would you model data variables variance on common scheme? SQL
  • Pandas plotting two graphs on one scale
  • Fluent Nhibernate: Trying to create entity with composite key that is also the keys for two referenc
  • Need advice in designing tables in SQL-Server
  • JFreeChart BarChart - Category Markers
  • Regex: Match everything except backreference
  • PostgreSQL 9.1 timezones
  • ResponseBuilder is not working when used with entity object
  • Escaping single quotes in JDBC with MySql
  • How to plot large time series (thousands of administration times/doses of a medication)?
  • How to make R's read_csv2() recognise the text characters properly
  • pillow imaging ImportError
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • Loading .coffee files via a view in Rails
  • C: Incompatible pointer type initializing
  • Create DicomImage from scratch using Dcmtk
  • Seeking advice on Jetty HttpClient Hang
  • Why is an OPTIONS request sent to the server?
  • Spring security and special characters
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Circular dependency while pushing http interceptor
  • Compare two NSDates in iPhone
  • AngularJs get employee from factory
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • How to load view controller without button in storyboard?