4

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!

Zoyt
  • 4,809
  • 6
  • 33
  • 45

2 Answers2

3

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.

Community
  • 1
  • 1
EthanB
  • 4,239
  • 1
  • 28
  • 46
1

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.

Matt Lacey
  • 8,227
  • 35
  • 58
  • Did you ever found out how to display e.g. a Word file in the WKWebView via the `loadData:MIMEType:characterEncodingName:baseURL:` method? – Pieter Meiresone Mar 21 '16 at 12:29
  • 1
    Hi Pieter, I ended up downloading the file I wanted to open to a temporary directory on the device, and then using the `loadFileURL` method instead of `loadData`. Seems to work well even though it's a bit of a roundabout way of doing it. – Matt Lacey Mar 21 '16 at 23:04
  • Indeed, that method works (just verified it). Thank you for the response! – Pieter Meiresone Mar 21 '16 at 23:31