4

He guys. I want the website to open in reading mode. I want it to open without unnecessary ads and buttons. How can I do that on webView. Sorry for my very bad English. Thanks.

Fatih Lale
  • 51
  • 1
  • 8
  • Dupe? https://stackoverflow.com/questions/4864883/safaris-reader-mode-open-source-solution – Neil Jul 14 '17 at 12:12

2 Answers2

4

UPDATE FOR SWIFT 4, iOS 11

The SFSafariViewController init function that takes an entersReaderIfAvailable parameter has been replaced by one that takes an SFSafariViewController.Configuration property. To get the old behaviour you can replace the code used in answers above by this:

let urlString = "http://www.google.com"
let url = URL(string: urlString)!
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
let safariVC = SFSafariViewController(url: url, configuration: config)
present(safariVC, animated: true, completion: nil)

This will do the trick!

JillevdW
  • 1,087
  • 1
  • 10
  • 21
3

First thing you cannot enable "Reader" mode for WKWebView or UIWebView. You need to use SFSafariViewController

Then you need to set entersReaderIfAvailable to true when initializing the instance.

Here an example :

    let urlString = "http://google.com"
    let url = URL(string: urlString)
    let safariVC = SFSafariViewController(url: url!, entersReaderIfAvailable: true)
    present(safariVC, animated: true, completion: nil)
Fares Benhamouda
  • 589
  • 8
  • 21