Architecture

  • API is identical on OS X and iOS.
  • Uses the fast Nitro JS engine on iOS (unlike UIWebView), including fourth tier LLVM JIT.
  • WKWebView has its own process(es), separate from the main app process.
  • Each page gets its own process up to an unspecified limit, at which point pages start sharing processes.

WKWebView

  • WKWebViewConfiguration class encapsulates all configuration so that it can be shared among multiple instances of WKWebView.
  • Properties (title, URL, loading, estimatedProgress) are KVO-compliant.

Customizing Page Loading

Gestures

  • allowsBackForwardNavigationGestures property enables left/right swipe gestures for navigation.
  • Set allowsMagnification property on NSScrollView for double tap and pinch to zoom. UIScrollView does this automatically with no additional configuration.

Customizing Webpage Content

  • Use WKUserContentController (userContentController property on WKWebViewConfiguration) to inject user scripts into web pages and register handlers for script messages.
  • User scripts (see WKUserScript) are scripts written in JS and are generally used to modify the DOM.
    • Debugged using the Safari web inspector.
  • Script messages (see WKScriptMessage) are sent as JSON from the web page to your app and are automatically converted into Objective-C types.

The modern WebKit API, including WKWebView and all associated classes are part of the open source WebKit project. The source code for these classes can be found here.