gpt4 book ai didi

wkwebview - 用于简单 WKWebView 的 loadHTMLString 在运行时因错误 WebPageProxy::processDidTerminate: (pid 0) 而崩溃,原因 3

转载 作者:行者123 更新时间:2023-12-02 18:48:46 25 4
gpt4 key购买 nike

我正在尝试使用带有单个按钮的简单 WKWebView,单击该按钮后应通过 JavaScript 回调到 Swift。但是,我在 Xcode 控制台中看到以下日志,并且 View 加载了空的 WKWebView:

  • [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::processDidTerminate: (pid 0), reason 3
  • [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::dispatchProcessDidTerminate: reason = 3
  • [pageProxyID=5, webPageID=6, PID=84636] WebPageProxy::processDidTerminate: (pid 84636), reason 3
  • [pageProxyID=5, webPageID=6, PID=84636] WebPageProxy::dispatchProcessDidTerminate: reason = 3
  • [pageProxyID=5, webPageID=6, PID=84636] WebPageProxy::tryReloadAfterProcessTermination: process crashed andthe client did not handle it, not reloading the page because wereached the maximum number of attempts

我初始化 WKWebView 和设置回调的代码如下所示:

   override func viewDidLoad() {
super.viewDidLoad()
let config = WKWebViewConfiguration()
config.userContentController.add(self, name: "callback")
wkWebView = WKWebView(frame: self.view.frame, configuration: config)
wkWebView.autoresizingMask = [.height, .width]
self.view.addSubview(wkWebView)

let htmlStr = "<!DOCTYPE html><html><body><button type=\"button\" onclick=\"myFunction()\">My Button</button><script type=\"text/javascript\">function myFunction() { window.webkit.messageHandlers.callback.postMessage('clicked!'); }</script></body></html>"
self.wkWebView.loadHTMLString(htmlStr, baseURL: Bundle.main.resourceURL)
}

最佳答案

花了一段时间才明白——因为我的应用是沙盒化的——我需要在 Signing & Capabilities 下启用网络连接,这反过来又为启动 WKWebView 的项目添加了适当的权利,其中包含期待已久的 My按钮我现在也能在点击此按钮时收到回调!

Capabilities to enable

Sample App Launched with button

希望这对处于相同情况的人有所帮助。

关于wkwebview - 用于简单 WKWebView 的 loadHTMLString 在运行时因错误 WebPageProxy::processDidTerminate: (pid 0) 而崩溃,原因 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67067390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com