6
votes

Apple's documentation suggests using WkWebView for new development, although it seems to have a typo where it recommends WKWebView over UIWebView in the mac developer library.

For new development, employ this class instead of the older UIWebView class.

The typo is probably because they are trying to unify the OSX and iOS interface to the web view by using the same header for both.

However, WKWebView doesn't have all the functionality that WebView has in OSX. For example, you can get access to DOM nodes in the native interface in WebView but I don't see any way of doing this from Swift/Objective-C in WKWebView.

For my purposes, it seems like WebView is what I need, but I'm weary of starting a project that relies on an API that will be removed. However, I don't see any mention of intent to deprecate WebView anywhere in the headers or the documentation.

What makes this even more confusing is the WebKit Framework Reference makes reference to both WK and older web view APIs without clarifying anything.

WKWebView

A WKWebView object displays interactive web content, such as for an in-app browser.

WebView

WebView is the core view class in the WebKit framework that manages interactions between the WebFrame and WebFrameView classes.

Is WebView going away in OSX?

2

2 Answers

3
votes

Its not a false alarm. Apple moved Safari off of UIWebView/WebView in 6.0, so security fixes simply aren't happening in the old class as much. For that reason alone you should not use it for new stuff. Apple has been incrementally improving it with every OS release so much is now do-able with private extensions (file:// access, downloads, etc)

That being said, it won't be fully equivalent to old WebView. You can't directly access the DOM anymore because the Network/Rendering/UI processes were split up and you create locks by making element references like that. Use the postMessage() message handler and wkwebview.evaluateJavaScript() and callback-ish/promisy JS code between those two pillars to deal with web<>native interaction asynchronously.

2
votes

Important

Starting in iOS 8.0 and OS X 10.10, use WKWebView to add web content to your app.
Do not use UIWebView or WebView.

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