Build a WebView

Once you have a Portal instance and you have generated a wallet, you can now build a web view to interact with dApps using the Portal wallet.

In the example below, we have a button that initializes Portal's WebViewController and adds it as a child view controller.

import PortalSwift

class ViewController: UIViewController {
  public var portal: Portal?

  @IBAction func handleWebview(_ sender: UIButton) {
    let webViewController = WebViewController(
      portal: portal!,
      url: URL(string: "https://app.uniswap.org/#/swap")!,
      onError: { (result: Result<Any>) -> Void in
        // ❌ Handle any errors from the web view.
      }
    )

    // Install the WebViewController as a child view controller.
    addChild(webViewController)

    let webViewControllerView = webViewController.view!
    view.addSubview(webViewControllerView)

    webViewControllerView.translatesAutoresizingMaskIntoConstraints = false
    webViewControllerView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
    webViewControllerView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    webViewControllerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    webViewControllerView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
    webViewController.didMove(toParent: self)

    // ✅ The web view is now running! 🙌
  }
}

And thats it! Remember that you will need a portal instance to start the web view and you will also need to initialize Portal with autoApprove: true if you want the web view to auto-approve transactions.

Next, let's explore how to use Portal's Swaps integration to perform swaps directly from your iOS app.

Last updated