In the example below, we have a button that initializes Portal's WebViewController and adds it as a child view controller.
importPortalSwiftclassViewController:UIViewController {publicvar portal: Portal?@IBActionfunchandleWebview(_sender: UIButton) {let webViewController =WebViewController( portal: portal!, url: URL(string:"https://app.uniswap.org/#/swap")!, onError: { (result: Result<Any>) ->Voidin// ❌ 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.