Links

WebKit API in a nutshell

WebKit API (for a quick recap, WebKit is a layout and rendring engine for web that's used by Safari, Dashboard, Mail, and many other Apple applications) replaces the traditional UIWebView with WKWebView with lots of powerful features i.e;
  • Responsive scrolling with 60 frames/sec
  • Power of JS Nitro engion (the engine formerly known as SquirrelFish)
  • Built-in multi gesture
  • App-Web Page communication
  • Automatic Multi-process Architecture - means web view have saperate process alike the app itself
  • Energy efficient
  • It is configurable with WKWebViewConfiguration class
Some basic WKWebView features;
  • Its actions and navigation flow can be easily configurable
  • Its properties can be easily accessable (with KVO as well), e.g; Active page title, URL, estimated progress, etc.
  • With WKNavigationDelegate - its actions can be easily managed same like UIWebView, i.e; app will be notified for url will/did change and page did finish loading
  • WKNavigationDelegate can also tell about, navigation type, source frame, destination frame, etc. in a WKNavigationAction object
  • WKNavigationResponse is the response object, it also have some useful properties as well
  • Configurable Navigation Gestures for back and forward options
Customizing web page content within WKWebView can be done by WKUserContentController which is part of WKWebViewConfiguration. The same can be done by two ways, i.e;
  1. User Sctipts - to take some JS and inject it into the web page, it can executed both start and end of dom loading
  2. Script Messages - are the messages that user scripts send back to the app, it can carry JSON as well
    • To recive Script Messages we need to register WKScriptMessageHandler protocol and messages can be sent by a simple JS call, i.e; window.webkit.messageHandlers.{NAME}.postMessage()
    • The recived message is an object of WKScriptMessage with contains; body, webView(reference to the sender web view) and name
    • Web page itself can post the Script Message if their JS are coded to do so
    • We need to be aware of security risks because any JS can call a Script Message

Post a Comment