Xcode 9 Gm - Wkwebview Nscoding Support Was Broken in Previous Versions

Xcode 9 GM - WKWebView NSCoding support was broken in previous versions

The error is correct behavior, and not a bug in Xcode 9. Although WKWebView was introduced in iOS 8, there was a bug in -[WKWebView initWithCoder:] that was only fixed in iOS 11, which always crashed at runtime and thus prevented configuring one within Interface Builder.

https://bugs.webkit.org/show_bug.cgi?id=137160

Rather than allow developers to build something in IB that would be broken at runtime, it is a build error. It's an inconvenient limitation since iOS 11 was only recently released, but there's really no other good option.

The workaround for older deployment targets is to continue to add the WKWebView in code, as @fahad-ashraf already described in his answer:

https://developer.apple.com/documentation/webkit/wkwebview

How to use webview in iOS 10 or lower versions?

Currently I'm using WKWebView, but it is supporting from iOS 11 onwards. So if i want to use web view in iOS 10 or lower versions what is the solution.

This is not true. WKWebView is supported from iOS 8 onwards.

WKWebView vs UIWebView

You can simply create and add a WKWebView via code.

If you want a visual representation for layout purposes in your Storyboard, here is one way to do it.

Add a standard UIView in your view controller in your Storyboard. This will act as a "holder" for your web view. Connect it to an IBOutlet, then in viewDidLoad add an instance of WKWebView as a subview of that "holder" view.

class MyViewController: UIViewController, WKNavigationDelegate {

// standard UIView, added in Storyboard
@IBOutlet weak var webViewHolder: UIView!

// instance of WKWebView
let wkWebView: WKWebView = {
let v = WKWebView()
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()

override func viewDidLoad() {

super.viewDidLoad()

// add the WKWebView to the "holder" UIView
webViewHolder.addSubview(wkWebView)

// pin to all 4 edges
wkWebView.topAnchor.constraint(equalTo: webViewHolder.topAnchor, constant: 0.0).isActive = true
wkWebView.bottomAnchor.constraint(equalTo: webViewHolder.bottomAnchor, constant: 0.0).isActive = true
wkWebView.leadingAnchor.constraint(equalTo: webViewHolder.leadingAnchor, constant: 0.0).isActive = true
wkWebView.trailingAnchor.constraint(equalTo: webViewHolder.trailingAnchor, constant: 0.0).isActive = true

// load a URL into the WKWebView
if let url = URL(string: "https://google.com") {
wkWebView.load(URLRequest(url: url))
}

// from here on out, use wkWebView just as if you had added it in your storyboard

}

}


Related Topics



Leave a reply



Submit