How to stop loading images in UIWebView?
2 answers
- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request
{
NSURL *url = [request URL];
BOOL blockURL = [[FilterMgr sharedFilterMgr] shouldBlockURL:url];
if (blockURL) {
NSURLResponse *response =
[[NSURLResponse alloc] initWithURL:url
MIMEType:@"text/plain"
expectedContentLength:1
textEncodingName:nil];
NSCachedURLResponse *cachedResponse =
[[NSCachedURLResponse alloc] initWithResponse:response
data:[NSData dataWithBytes:" " length:1]];
[super storeCachedResponse:cachedResponse forRequest:request];
[cachedResponse release];
[response release];
}
return [super cachedResponseForRequest:request];
}
This is the code for part of this
Hope it helps
+2
source to share
Then remove all image tages using below code then after load your html string into webview
NSString *str =@"<ul><img src=\"some url\"/><li>Tiny pores in leaves or stems, which water and gas can pass. </li><li>Plants can reduce the amount of water that is passed by closing the stomates during the hottest parts of the day or curling their leaves up to reduce exposure.</li></ul>";
NSLog(@"before--%@",str);
NSRange r;
while ((r = [str rangeOfString:@"<img[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
str = [str stringByReplacingCharactersInRange:r withString:@""];
NSLog(@"after---%@",str);
0
source to share