-1

I want to load privacy policy (simple string) from server say, https://*****.com/privacy-policy.html to my app.

What I have tried till now is given below:

class TermsAndConditionsDetailViewController: UIViewController, WKNavigationDelegate {
    @IBOutlet weak var contentView: UIView!
    var webView: WKWebView!

    func webView(_ webView: WKWebView,
                 didFinish navigation: WKNavigation!) {
        print("loaded")
    }
    override func viewDidLoad() {
    super.viewDidLoad()

        webView = WKWebView()
        contentView.addSubview(webView)
        let myURL = URL(string: "https://***.com/privacy-policy.html")
        let myRequest = URLRequest(url: myURL!)
        webView.navigationDelegate = self

        //I have tried these both one by one
        webView.loadHTMLString("", baseURL: myURL)
        webView.load(myRequest)
     } 
}

When i run this code "loaded" gets printed after 2 - 3 seconds but it doesn't show anything on the screen. I have been searching this issue for some time now and have tried to play around with the code. I have cross checked the constraints of all view specially contentView, but no luck.

kinza
  • 535
  • 11
  • 31

1 Answers1

1

You forget to add frame for your WKWebView

just add

webView = WKWebView(frame: self.contentView.frame)

after

webView = WKWebView()

and it will work fine.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165