ios - 我们可以在 native iOS 应用程序中创建 localhost

标签 ios swift uiwebview

我必须在 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/

相关文章:

ios - 使用 Cocoapods 进行 Xcode 单元测试

swift - 如何在 Swift 中扩展协议(protocol)

ios - 如何使用 Realm 和 UICollectionView 防止 NSInternalInconsistencyException

ios - ScrollBar 在手动滚动时添加垂直偏移

iphone - 在 SQLite 数据库的 uiwebview 中显示 HTML 文件?

ios - 在 iOS 应用程序中嵌入 HTTP 服务器有什么优势?

ios - 如何将应用程序日志写入文件并获取它们

ios - 他们使用什么控件以及如何使用?

ios - 在 iOS 中以后台模式运行任务

ipad - 两根手指触摸UIWebview,使我的应用崩溃