WKWebView (iOS Swift)

Nitish Kumar
2 min readMay 8, 2021

--

What is wkwebview?

“An object that displays interactive web content, such as for an in-app browser.”

In this story, we learn very basic of wkwebview in two parts level 1 and 2.

LEVEL 1-

In level 1 we load a webview and show little how it works.

  1. For this we decalre a wkwebview and wkwebviewConfiguration object.

What is wkwebviewConfiguration?

A WKWebViewConfiguration object provides information about how to configure a wkwebview object. Use your configuration object to specify:

  • The initial cookies to make available to your web content
  • Handlers for any custom URL schemes your web content uses
  • Settings for how to handle media content
  • Information about how to manage selections within the web view
  • Custom scripts to inject into the webpage
  • Custom rules that determine how to render content

2. create a function i.e. loadview to set wkwebview frame and delegate.

3. By using wkNavigationDelegate we can trace wkwebview navigation.

Result -

LEVEL 2-

In level 2 we try to load webview on webview .

Meanwhile i will load youtube webview to my medium webview. which we created previously.

  1. declare wkwebview for new webview.
  2. add some webview configuration i.e. allowsInlineMediaPlayback set to true and mediaTypeRequringUserActionForPlayback to null.

allowsInlineMediaPlayback → A Boolean value that indicates whether HTML5 videos play inline or use the native full-screen controller.

mediaTypeRequringUserActionForPlayback → The media types that require a user gesture to begin playing.

3. set frame for new webview.

4. add new webview frame to main view.

Output of level 1 and 2 -

Privacy — Photo Library Additions Usage Description

complete code-

Sources-

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

Thanks!! Hope this will help you to learn. Please take a minute to review.

--

--

Nitish Kumar
Nitish Kumar

Written by Nitish Kumar

I developed and maintain applications aimed at a range of iOS devices including mobile phones and tablet computers.

No responses yet