开发者

Show contents of a zip file in a WebView

I want to have a WebView that displays some static files from the application bundle. Since I have a large number of small files, I'd like to pack them all into a compressed archive so the application doesn't take up too much space. What's the best开发者_开发问答 way to make this happen?


This should help you out: http://code.google.com/p/ziparchive/

To display data in the WebView:

On Mac OS X use WebFrame's loadHTMLString:baseURL:

On iOS use UIWebView's loadHTMLString:baseURL:


What you probably want to do, is implement an NSURLProtocol subclass that will resolve relative URLs by reading them from the zip archive. That way, you only need to initially read the "main" HTML file from the zip into memory, and the others will be read in on demand. To get WebKit to use your custom URL protocols for resolving relative paths, you could instantiate the WebView like this:

[[web_view mainFrame] loadHTMLString:your_main_html baseURL:[[NSURL alloc] initWithString:@"zip:///"]];

Apple has a really good example of combining a custom URL protocol with a WebView here:

https://developer.apple.com/library/mac/#samplecode/SpecialPictureProtocol/Introduction/Intro.html#//apple_ref/doc/uid/DTS10003816

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜