Currently, I'm using WKWebView
to do loadHTMLString(_ string: String, baseURL: URL?)
and for some reasons, it wont load the content page from the source. However, If I switch to UIWebView
and do the same thing and surprisedly, content page can be displayed successfully. Below are my codes:
This is WKWebView:
if let html = try? String(contentsOfFile: page.href, encoding: String.Encoding.utf8) {
wkWebview.loadHTMLString(html, baseURL: URL(string:book.resourceDir! + "/"))
}
This is UIWebView:
if let html = try? String(contentsOfFile: page.href, encoding: String.Encoding.utf8) {
webView.loadHTMLString(html, baseURL: URL(string:book.resourceDir! + "/"))
}
Notice: the html
and baseURL
are identical for both uiwebview
and wkwebview
.
Have anyone had this problem and have any ideas about it. All comments are welcomed.