HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 如何使用iOS中的图像缓存整个网页大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在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中的图像缓存整个网页所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。