Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView vs WKWebView on OSX

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?

like image 459
vopilif Avatar asked Dec 18 '15 21:12

vopilif


People also ask

Is WKWebView same as Safari?

WKWebView - This view allows developers to embed web content in your app. You can think of WKWebView as a stripped-down version of Safari. It is responsible to load a URL request and display the web content. WKWebView has the benefit of the Nitro JavaScript engine and offers more features.

Is WKWebView deprecated?

Since then, we've recommended that you adopt WKWebView instead of UIWebView and WebView — both of which were formally deprecated. New apps containing these frameworks are no longer accepted by the App Store.

What is macOS WebView?

WebView is the core view class in the WebKit framework that manages interactions between the WebFrame and WebFrameView classes. To embed web content in your application, you just create a WebView object, attach it to a window, and send a load(_:) message to its main frame. macOS 10.3–10.14 Deprecated.

Does Apple allow WebView app?

Apple will no longer allow applications on the App Store that include the UIWebview control. More details on timelines and potential solutions can be found below. What changed and how was I affected? Apple is no longer accepting new mobile applications that embed web content in a UIWebView control as of April, 2020.


1 Answers

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.

like image 193
kfix Avatar answered Oct 03 '22 00:10

kfix