当前位置:首页 > 操作系统 > Ios

ios开发 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];
}

 

原文:http://www.cnblogs.com/jackson-leung/p/4641157.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!