【发布时间】:2021-06-10 18:39:07
【问题描述】:
我正在尝试将基于 html 的本地网站加载到我的 macOS 应用程序中,但我遇到了问题,我在 iOS 中可以使用,但在 macOS 中无法使用。
我的 ViewController.swift 看起来像这样
import Cocoa
import WebKit
class ViewController: NSViewController, WKUIDelegate, WKNavigationDelegate {
var webView: WKWebView!
override func loadView() {
let webConfig = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfig);
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let htmlURL = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "website")!
webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL.deletingLastPathComponent())
}
}
应用程序运行,但随后我在 Xcode 的控制台中得到此输出:
WebPageProxy::tryReloadAfterProcessTermination: 进程崩溃并且客户端没有处理它,没有重新加载页面,因为我们达到了最大尝试次数
我正在尝试做的事情的文档似乎缺乏我想知道是否有人可以帮我解决这个问题。
【问题讨论】:
-
叫 uiDelegate 的家伙是什么来的?