问题
I'd like to use WKWebView instead of a UIWebView to display data on iOS. However, it seems that loadData:MIMEType:textEncodingName:baseURL: was removed in WKWebView.
Is there any way to mimic this functionality in WKWEbView?
Thanks!
回答1:
You could convert your NSData to NSString and use loadHTMLString:baseURL: (API Docs).
However, that method has issues with file-system base URLs in the latest beta: WKWebView not working in iOS 8 beta 4.
回答2:
As of iOS 9.0 and onwards WKWebView now has the same method:
- loadData:MIMEType:characterEncodingName:baseURL:
That said, I'm currently having issues with certain file types (MS Word) that worked in UIWebView but not in WKWebView.
来源:https://stackoverflow.com/questions/25799977/loaddatamimetypetextencodingnamebaseurl-in-wkwebview