Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I load a .webarchive into a UIWebView from an in-memory NSData?

I have an NSData containing a .webarchive blob that I'd like to load into a UIWebView. I know that this is possible (see this question), and I have it working if I first serialize it to disk and then load it with UIWebView's -loadRequest: method.

However, I'd prefer not to serialize to disk first since I already have the data in memory. I've tried to use -loadData:MIMEType:textEncodingName:baseURL: with the data, and various base URLs, but it always fails (nil, @"http://", the actual root path that the web archive contains, etc) to load.

Again, the same archive loads correctly if I bounce it to disk first and load via -loadRequest:, so I feel like something about the MIMEType (I'm using application/octet-stream) and/or the base URL is wrong. Anyone know what the incantation is?

like image 352
Ben Zotto Avatar asked Oct 17 '25 18:10

Ben Zotto


1 Answers

Using -loadData:... will work. The MIME type specified must be application/x-webarchive (not the generic "octet-stream"). If this is set correctly, both the text encoding and base URL can be just supplied as nil.

like image 50
Ben Zotto Avatar answered Oct 20 '25 08:10

Ben Zotto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!