您的位置:首页 > 产品设计 > UI/UE

uiweb实现缓存

2017-01-03 22:16 411 查看
 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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: