3
votes

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?

2
can you provide that html string formatNarayana
Maybe you can use this stackoverflow.com/questions/2067943/….simonbs
This may help you: [stop loading images][1] [1]: stackoverflow.com/questions/2598833/…Kanan Vora
@Narayana the html string format body part is something like <img src="some url" />tangqiaoboy

2 Answers

2
votes
- (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

0
votes
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);