WKWebView Example

Reference:
https://developer.apple.com/reference/webkit/wkwebview

Sample Code:

import UIKit
import WebKit

class ViewController: UIViewController , WKNavigationDelegate {

var webView : WKWebView!

override func viewDidLoad() {
  super.viewDidLoad()

  let adreq = "https://g.adspeed.net/ad.php?do=html&zid=xxxx"
  let url = NSURL(string: adreq)
  let request = NSURLRequest(URL: url!)

  webView = WKWebView(frame: self.view.frame)
  webView.navigationDelegate = self
  webView.loadRequest(request)

  self.view.addSubview(webView)
  self.view.sendSubviewToBack(webView)
}

override func didReceiveMemoryWarning() {
  super.didReceiveMemoryWarning()
}

// WKNavigationDelegate

func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
  print(error.localizedDescription)
}
func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
  print("Loading")
}
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
  print("Loaded")
}

}

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *