WebAppViewController

public class WebAppViewController: UIViewController, WKScriptMessageHandler

A WebAppViewController is the canonical way to show WebApps to users.

Important note: unless you call ensureWebViewInstantiated(), the web app is not created until the view controller is added to the view hierarchy! If you want to start loading the page before you show it to the user, call that method.

Simplest possible view controller:

class SimplestExampleWebAppViewController: WebAppViewController {

    override func createWebApp() -> WebApp { return SimplestExampleWebApp() }

    override func viewDidLoad() {
        // optional:
        // self.loggingDelegate = myWebAppViewControllerLoggingDelegate

        super.viewDidLoad()
        self.loadWebAppInitialURL()
    }

}
  • WebApp’s classes will be silent in the console unless you set this.

    Declaration

    Swift

    public weak var loggingDelegate: WebAppViewControllerLoggingDelegate?
  • The WKWebView instance created by this view controller, if it exists yet

    Declaration

    Swift

    public var webView: WKWebView?
  • The WebApp instance created by this view controller, if it exists yet

    Declaration

    Swift

    public var webApp: WebApp?
  • Subclasses must return a WebApp instance from this method. Unless you’re doing something sophisticated, the WebApp instance should generally not be created until this method is called, since the view may not be visible yet and we want to minimize memory usage.

    Declaration

    Swift

    public func createWebApp() -> WebApp
  • Load the initial URL specified in the web app. You’ll probably want to call this from viewDidLoad().

    Declaration

    Swift

    public func loadWebAppInitialURL()
  • Make sure the WebApp and WKWebView have been instantiated and configured

    Declaration

    Swift

    public func ensureWebViewInstantiated()