Chao Chao - 5 months ago 31
Swift Question

WKWebView don't show the website in swift with iOS 9.0

i try to use WKWebView, but it don' work.

here is my code

import UIKit
import WebKit

class WebviewVC: UIViewController, WKNavigationDelegate {

var webview: WKWebView?

// MARK: - ********** Lifecycle **********

override func viewDidLoad() {

webview = WKWebView(frame: view.bounds)
webview!.navigationDelegate = self
webview!.allowsBackForwardNavigationGestures = true

override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated.

//MARK: - ********** load url ***********

func loadUrl(urlStr: String) {
let url = NSURL(fileURLWithPath: urlStr)
let requestObj = NSURLRequest(URL: url)


i have seted the App Transport Security Settings -> Allow Arbitrary Loads to YES. but the webView also don't show the website.

pls help!

Lu_ Lu_

What is this:

let url = NSURL(fileURLWithPath: urlStr)

you should use:

let url = NSURL(string: urlStr)