uiweb实现缓存

来源:互联网 发布:淘宝网购买泓铭软件 编辑:程序博客网 时间:2024/06/07 01:22
 NSURL *url = [NSURL URLWithString:@"http://www.baidu.com/"];
    
    NSURLCache *urlCache = [NSURLCache sharedURLCache];
    
    [urlCache setMemoryCapacity:1*1024*1024];
    
    NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:60.0];
    
    NSCachedURLResponse *response=[urlCache cachedResponseForRequest:urlRequest];
    
    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
    if (response !=nil ) {
        [urlRequest setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
    }else
    {
        
    }
    
    [web loadRequest:urlRequest];
    
    [self.view addSubview:web];
0 0