WKWebView fails to load images and CSS using loadHTMLString(_, baseURL:)

前端 未结 10 846
抹茶落季
抹茶落季 2020-12-14 14:05

Apple\'s recommendation:

In apps that run in iOS 8 and later, use the WKWebView class instead of using UIWebView.

Thus, I have r

10条回答
  •  长情又很酷
    2020-12-14 14:58

    When I used UIWebview, I used baseURL as,

    let baseUrl = NSURL(string: Bundle.main.path(forResource: "cms", ofType: "html")!)! as URL
    
    webView.loadHTMLString(bodyPage, baseURL: baseUrl)
    

    But for the WKWebView, I used baseURL as

    let baseUrl = Bundle.main.bundleURL
    
    webView.loadHTMLString(bodyPage, baseURL: baseUrl)
    

    This works for me.

提交回复
热议问题