Skip to content

Instantly share code, notes, and snippets.

@PaulRosset
Last active November 25, 2022 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulRosset/cea982e09d09e609679b7e848e397674 to your computer and use it in GitHub Desktop.
Save PaulRosset/cea982e09d09e609679b7e848e397674 to your computer and use it in GitHub Desktop.
Spawning a IOS fullscreen Webview view
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, WKScriptMessageHandler {
var webView: WKWebView!
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
print("Hello world")
}
override func loadView() {
let wkPreferences = WKPreferences()
wkPreferences.javaScriptCanOpenWindowsAutomatically = true
let webConfiguration = WKWebViewConfiguration()
// Allow the webpage to perform events from Webpage to Mobile App
// Known as JSBridge
let contentController = WKUserContentController()
contentController.add(self, name: "nativeBridge")
webConfiguration.userContentController = contentController
webConfiguration.preferences = wkPreferences
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
// You can also replace by localhost URL!
let url = URL(string: "http://...")
let myRequest = URLRequest(url: url!)
webView.load(myRequest)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment