Initializing the WKWebView


  • Import the WebKit with the following command
    import WebKit
  • To avoid video playing in the native full-screen viewer, provide a custom WKWebViewConfiguration with the allowsInlineMediaPlayback property set to true.
    let webConfiguration = WKWebViewConfiguration()
    webConfiguration.allowsInlineMediaPlayback = true

Note

The media playback property must be set before initializing the WebView.

  • Initialize a WebView with the following configuration.
    let webView = WKWebView(frame: .zero, configuration: webConfiguration)
  • If you want the WebView to fill the entire screen without horizontal scroll bars, use the following command to set the WebView scroll view.
    webView.scrollView.isScrollEnabled = false
    webView.scrollView.contentInsetAdjustmentBehavior = .never

Note

You must set a custom user agent for the Embed SDK to work, otherwise, you will be directed to the "Join with app" page.

webView.customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4_2 like Mac OS X)
AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1"
  • After you create and configured the WebView, embed it in a ViewController, then set up a webViewContainerView in the Storyboard and add the WebView programmatically. 
    webView.translatesAutoresizingMaskIntoConstraints = false
    webViewContainerView.addSubview(webView)
    NSLayoutConstraint.activate([
        webView.leadingAnchor.constraint(equalTo: webViewContainerView.leadingAnchor),
        webView.trailingAnchor.constraint(equalTo: webViewContainerView.trailingAnchor),
        webView.bottomAnchor.constraint(equalTo: webViewContainerView.layoutMarginsGuide.bottomAnchor),
        webView.topAnchor.constraint(equalTo: webViewContainerView.layoutMarginsGuide.topAnchor)
    ])

Loading the BlueJeans Embed SDK

The BlueJeans Embed SDK requires an HTML page to be embedded, a sample page can be found here.

You can include this folder locally in your project. Once you initialize the WebView, you can load this page with the following code snippet, which contains there is an index.html page inside a WebView folder at the root level of the app.

if let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "WebView") {
    webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
}