3

我想用uiwebview来加载www.youku.com。但是,我只想加载没有图像的纯文本。换句话说,我想阻止 uiwebview 的图像。我检查了http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/并将其实现如下:

- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request
{
   NSURL *url = [request URL];
   BOOL blockURL = [url.absoluteString hasSuffix:@"jpg"] || [url.absoluteString hasSuffix:@"jpeg"] || [url.absoluteString hasSuffix:@"png"] || [url.absoluteString hasSuffix:@"gif"] || [url.absoluteString hasSuffix:@"ico"] || [url.absoluteString hasSuffix:@"JPG"] || [url.absoluteString hasSuffix:@"JPEG"];
   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];
}

使用上面列出的代码,我可以阻止一些带有 png 、 gif 、 jpg 等后缀的图像。但是,有些图片有特殊的 url 没有后缀,例如http://g4.ykimg.com/0100641F4650B6A053C841081E2CED75B89DFC-FF09-FE48-E9A9-783C7AD8EC42。对于这些特殊的 url,上面的代码将不起作用。那么,如果有人对如何检测特殊 url 是否与图像相关有好的想法?

4

0 回答 0