对于文本部分,我可以将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中的图像缓存整个网页所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)