我在这方面遇到了困难。我不太确定我做错了什么。
这是我为 iOS UIWebView 做的:
let url = Bundle.main.url(forResource: "index", withExtension: "html")
let request = NSURLRequest(url: url!)
webView.loadRequest(request as URLRequest)
不幸的是,这不适用于 OS X 应用程序。我找到了一些用于 Swift 2 的代码。我对其进行了一些更改以使其与 Swift 3 一起使用,但我仍然遇到错误。
let url = Bundle.main.url(forResource: "index", withExtension: "html")
self.webView.mainFrame.load(NSURLRequest(URL: NSURL(string: url)!))
我有哪些选择?提前致谢!
最佳答案
试试这个简单的步骤,对我有用
let urlpath = Bundle.main.path(forResource: "index", ofType: "html");
let requesturl = URL(string: urlpath!)
let request = URLRequest(url: requesturl!)
webView.mainFrame.load(request)
关于html - 在 macOS 应用程序中使用 Swift 3 在 WebView 中加载本地 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41378026/