3

I want to use UIWebView to load a html url, but don't load the image in the html.I want UIWebView just display the plain text in the html. And because of some reason, I can NOT change the html content before loading.

Is there any method to achieve this?

tangqiaoboy
  • 1,476
  • 1
  • 15
  • 32

2 Answers2

2
- (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];
}

It some part code from this

Hope it'll help

Alex Moskalev
  • 607
  • 7
  • 15
0
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);
Narayana Rao Routhu
  • 6,303
  • 27
  • 42