iosh5调试写一个webview

import UIKit
import WebKit

class ViewController: UIViewController,WKNavigationDelegate {
    
    @IBOutlet weak var webView: WKWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let url = URL(string: "https://www.baidu.com/")
        let myRequest = URLRequest(url: url!)
        webView.load(myRequest)
    }
    
    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}


然后
增加 App Transport Security Settings dictionary类型
在里层增加 Allow Arbitrary Loads bool 类型 为YES
在这里插入图片描述

发布了190 篇原创文章 · 获赞 37 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/sufubo/article/details/104044713