高手superior

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

 

posted on 2015-07-12 16:46  高手superior  阅读(212)  评论(0编辑  收藏  举报