我必须在 UIWebView 或 WKWebView 中使用 http 协议(protocol)加载 html 文件。这是我使用 WKWebView 的代码:
import UIKit
import WebKit
class ViewController: UIViewController,WKUIDelegate {
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: self.view.frame, configuration: webConfiguration)
webView.uiDelegate = self
let path = URL(fileURLWithPath: "index.html")
let myURL = path
let myRequest = URLRequest(url: myURL)
webView.load(myRequest)
self.view.addSubview(webView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
是否可以从 native 包解析 http 协议(protocol)?
最佳答案
是的,这是可能的。您需要在应用程序中运行 HTTP 服务器才能实现这一点。就我个人而言,我建议使用 GCDWebServer .
关于ios - 我们可以在 native iOS 应用程序中创建 localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47344345/