0

我让我的 WKWebview 加载这样的网页:

class SafariExtensionViewController: SFSafariExtensionViewController, WKNavigationDelegate {

    static let shared = SafariExtensionViewController()
    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        self.preferredContentSize = NSMakeSize(400, 600)
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.navigationDelegate = self
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        let myURL = URL(string: frameUrl)
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
        os_log("EXTEST the WKWebview has loaded")
    }

}

在我的 localhost web 服务 js 文件中,我添加了一个发布消息事件

window.parent.postMessage(message, '*')

现在我尝试在我的快速代码中收听这个事件,这可能吗?

4

1 回答 1

0

可以对 JavaScript 回调做出反应。检查方法WKWebViewevaluateJavaScript:

https://developer.apple.com/documentation/webkit/wkwebview/1415017-evaluatejavascript

于 2019-12-12T07:37:41.247 回答