Before we jump into implementing WKWebView I would first introduce you to why you want to use it. WKWebView helps you when you want to load a webpage inside your app without throwing users to a third party browser outside of your app.
Let’s start coding,
Step 01: First Import WebKit
import WebKit
Step 02: Add ‘WKNavigationDelegate’ to your declaration of ViewController Class
WKNavigationDelegate
It will look something like this:
class ViewController: UIViewController, WKNavigationDelegate {
}
Step 03: Now create two variables for loading webView and one for button which will close webView
var webView: WKWebView!
var closeWebViewUIButton = UIButton(type: .system) as UIButton
Step 04: Now naviagte to your ViewDid Load method
override func viewDidLoad() {
super.viewDidLoad()
}
Step 05: Now in your ViewDidLoad method add the following code, Which will load WKWebView. You can change the URL as per your preference.
(more…)Continue Reading Post