Running localhost for WKWebkitView

Viewed 5937

Previously, when loading local html content into UIWebView, it would automatically run localhost/server in the background. This server emulation would enable me to load dynamic content through json, for example. Example code below;

@IBOutlet weak var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        webView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "www/index", ofType: "html")!)))
}

I am now trying to implement this into a WKWebView. I can load local html content, but unlike UIWebView, WKWebView does not emulate localhost/server, so I cannot do things like before, such as dynamically load content with json etc. How would I go about running local html content through localhost? If UIWebView had that feature automatically, surely WKWebView should have it right? Code below.

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    webView.load(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "www/index", ofType: "html")!)))
}

Note: I am using Xcode 9 for this, so WKWebview is being added through Storyboard and the referenced as an outlet.

Many thanks in advance to anybody who can help me with this.

1 Answers
Related