我想使用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等。 但是,某些图片具有不带后缀的特殊网址,例如http://g4.ykimg.com/0100641F4650B6A053C841081E2CED75B89DFC-FF09-FE48-E9A9-783C7AD8EC42。 对于这些特殊网址,上述代码将无法使用。 那么,如果有人对如何检测特殊网址是否与图像相关有好的想法呢?