我让我的 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, '*')
现在我尝试在我的快速代码中收听这个事件,这可能吗?