iPhone UIWebView缓慢加载到本地HTML文件 [英] iPhone UIWebView slow loading to local HTML files

查看:177
本文介绍了iPhone UIWebView缓慢加载到本地HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,需要在保存页面的整个HTML之后(完全)缓存网页以及CSS文件和图像(通过链接将每个文件与HTML文件一起存储)。

I'm developing an app that requires caching web pages (completely) along with their CSS files and images after saving the entire HTML of the page (going through the links to store each file along with the HTML file).

在离线查看HTML文件时, UIWebView 需要很长时间才能加载页面,因为我已经离线,该文件与其CSS和图像一起在磁盘上。

While viewing the HTML file offline, UIWebView takes a long time to load the page, given that I'm already offline, and the file is on disk along with its CSS and images.

我正在使用此代码加载文件:

I'm using this code to load the file:

  NSData *htmlData = [NSData dataWithContentsOfFile:htmlFilePath];
  [wView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:self.htmlFolderPath isDirectory:YES]];

是否还有其他方法可以将文件加载到 UIWebView 可以加载得更快吗?

Is there any other means of loading the file to the UIWebView that can load it faster?

PS:它在模拟器上加载速度非常快(离线)但在设备上需要很长时间(考虑到它已经离线)缓存文件)

P.S: it loads very fast on simulator (offline) but on device it takes a long time (considering its an already offline cached file)

感谢您的帮助。

推荐答案

您的解决方案实际上缓存除html文件以外的东西,意思是图片,CSS等,并在html页面中重新链接它们?我猜你正在下载并缓存html页面和外部资源,然后UIWebView正在加载那个html并且仍然要加载外部资源。这可以解释模拟器上的快速性能以及设备上较慢的性能。

Is your solution actually cache things other than the html file, meaning pictures, css, etc, AND relinking them in the html page? I am guessing that you are downloading and caching the html page and external resources then the UIWebView is loading that html and still going out to load the external resources. That would explain the fast performance on the simulator and the slower performance on device.

这是一个专门用于完成您要做的事情的库: ASIWebPageRequest

Here is a library designed to do exactly what you are trying to do: ASIWebPageRequest.

还应该注意,它可能只是磁盘I / O瓶颈的情况。我知道在我的项目中,我在一个uitableview中加载大图像,甚至在它们被缓存之后我注意到它们从磁盘上拉下来时会有相当多的滞后因为它们太大了。

It should also be noted that it could simply be a case of disk i/o bottlenecking. I know on my project, I was loading large images in a uitableview and even after they were cached I noticed quite a bit of lag when pulling them off the disk because they were so big.

这篇关于iPhone UIWebView缓慢加载到本地HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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