iphone – 如何使用iOS中的图像缓存整个网页

iphone – 如何使用iOS中的图像缓存整个网页,第1张

概述我正在iOS上的图像文字混合页面上工作.我知道我可以使用UIWebView实现目标.但问题是用户可能需要离线阅读页面. 对于文本部分,我可以将html保存到磁盘,并将其加载到离线模式. 但图像怎么样?是否可以将图像缓存到磁盘,UIWebView仍然可以显示它们? 谢谢! ASIHTTPRequest project有一个名为ASIWebPageRequest的类,旨在完全符合您的要求.如果您还可以 我正在iOS上的图像文字混合页面上工作.我知道我可以使用UIWebVIEw实现目标.但问题是用户可能需要离线阅读页面.
对于文本部分,我可以将HTML保存到磁盘,并将其加载到离线模式.
但图像怎么样?是否可以将图像缓存到磁盘,UIWebVIEw仍然可以显示它们?

谢谢!

解决方法 ASIHTTPRequest project有一个名为ASIWebPageRequest的类,旨在完全符合您的要求.如果您还可以添加额外的依赖项目,那么我认为这是一个很好的解决方案: ASIWebPageRequest.

在我上面喜欢的页面上,有一些很好的例子,如何使用它,但我会包括其中一个在这里完整性:

- (IBAction)loadURL:(NSURL *)url{   // Assume request is a property of our controller   // First,we'll cancel any in-progress page load   [[self request] setDelegate:nil];   [[self request] cancel];   [self setRequest:[ASIWebPageRequest requestWithURL:url]];   [[self request] setDelegate:self];   [[self request] setDIDFailSelector:@selector(webPageFetchFailed:)];   [[self request] setDIDFinishSelector:@selector(webPageFetchSucceeded:)];   // Tell the request to embed external resources directly in the page   [[self request] setUrlReplacementMode:ASIReplaceExternalResourcesWithData];   // It is strongly recommended you use a download cache with ASIWebPageRequest   // When using a cache,external resources are automatically stored in the cache   // and can be pulled from the cache on subsequent page loads   [[self request] setDownloadCache:[ASIDownloadCache sharedCache]];   // Ask the download cache for a place to store the cached data   // This is the most efficIEnt way for an ASIWebPageRequest to store a web page   [[self request] setDownloadDestinationPath:      [[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:[self request]]];   [[self request] startAsynchronous];}- (voID)webPageFetchFailed:(ASIhttpRequest *)theRequest{   // ObvIoUsly you should handle the error properly...   NSLog(@"%@",[theRequest error]);}- (voID)webPageFetchSucceeded:(ASIhttpRequest *)theRequest{   Nsstring *response = [Nsstring stringWithContentsOffile:      [theRequest downloadDestinationPath] enCoding:[theRequest responseEnCoding] error:nil];   // Note we're setting the baseURL to the url of the page we downloaded. This is important!   [webVIEw loadHTMLString:response baseURL:[request url]];}
总结

以上是内存溢出为你收集整理的iphone – 如何使用iOS中的图像缓存整个网页全部内容,希望文章能够帮你解决iphone – 如何使用iOS中的图像缓存整个网页所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1085571.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存