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")
}

}

Comments (0)

› No comments yet.

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pingbacks (0)

› No pingbacks yet.