iOS中离线网站的最佳实践 [英] Best practice for offline website in iOS

查看:122
本文介绍了iOS中离线网站的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个需要下载大量html5内容的应用。基本上它的工作方式类似于您在iPad上看到的杂志应用程序,除了使用图像外,它将使用UIWebViews和HTML。

I'm building an app that requires downloading a lot of html5 content. Essentially it works similar to the magazine apps you see for iPad, except instead of using images, it will use UIWebViews and HTML.

我的问题是什么是存储它的最佳方法。我想的是一个下载的zip文件,它被解压缩到包中并包含h​​tml文件,图像,css等,或者将所有html放在数据库中,只是将图像,CSS,视频等下载并放入捆绑。

My question is what would be the best method for storing this. I was thinking either a downloaded zip file that gets unzipped into the bundle and contains the html files, images, css, etc. or putting all the html in the database and just having the images, css, videos, etc. downloaded and put in the bundle.

一些注意事项:

许多链接将是设备的本地链接,但有些链接将是外部网站。

Many links will be local to the device, but some will be to outside sites.

我需要能够对所有html内容进行全文搜索。

I will need to be able to do full text search on all html content.

内容的大小会有所不同。

The size of the content will vary.

在旁注中,我很乐意被指出关于使用UIWebViews设置分页的正确方向。可能有很多UIWebViews。

On a side note, I would love to be pointed in the right direction as far as setting up paging with UIWebViews. Potentially a lot of UIWebViews.

谢谢,
Brandon

Thanks, Brandon

推荐答案

您可以先下载一个反映网站图片结构的文件,css,htmls。

You could download first an file that reflects the structure of the website images, css, htmls.

然后你解析这个文件并开始下载每个文件并将它们保存到文档目录中(你不能保存在数据库中,因为你可能有大图像而且会很慢你可以保存它们的路径)。其他只是对本地html请求。

Then you parse this file and start download each file and save them to documents directory (you don't save in database because you could have big images and that will be slow you could save the paths of them). Afther thad just do an request to the local html.

编辑:
您可以在webView委托中捕获请求,看看它是内部还是外部

You can catch the request in the webView delegate and see if it is internal or external


webView:shouldStartLoadWithRequest:navigationType:
在Web视图开始加载
内容之前发送。

webView:shouldStartLoadWithRequest:navigationType: Sent before a web view begins loading content.


  • (BOOL)web视图:(的UIWebView *)webView的shouldStartLoadWithRequest:(的NSURLRequest
    *的)请求navigationType:(UIWebViewNavigationType)navigationType

UIWebViewDelegate协议参考

这篇关于iOS中离线网站的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆