zoukankan      html  css  js  c++  java
  • iOS WKWebView缓存清理

    1、在发起请求时直接从原始地址请求,不读缓存数据 : NSURLRequestReloadIgnoringCacheData

        self.webView = [[WKWebView alloc]initWithFrame:f configuration:configuration];
        _webView.navigationDelegate = self;
        _webView.backgroundColor = [UIColor clearColor];
        _webView.allowsBackForwardNavigationGestures =YES;//打开网页间的 滑动返回
        _webView.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
        //监控进度
        [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
        [_webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:nil];
        [self.view addSubview:_webView];
      //进度条
        _progressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
        _progressView.tintColor = _progressViewColor;
        _progressView.trackTintColor = [UIColor clearColor];
        _progressView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 3.0);
        [_webView addSubview:_progressView];
    
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:_url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0];
        //加密header部分
        NSString *headerContentStr = [[HeaderModel new] modelToJSONString];
        NSString *headerAESStr = aesEncrypt(headerContentStr);
        [request setValue:headerAESStr forHTTPHeaderField:@"header-encrypt-code"];
        [_webView loadRequest:request];
    

    2、清除缓存

        if(@available(iOS 9.0, *)) {
            NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
            NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
            [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
                NSLog(@"清楚缓存完毕");
            }];
        }else{
            [[NSURLCache sharedURLCache] removeAllCachedResponses];
            [[NSURLCache sharedURLCache] setDiskCapacity:0];
            [[NSURLCache sharedURLCache] setMemoryCapacity:0];
        }
    
  • 相关阅读:
    MicroPython实例之TurnipBit开发板自动浇水实验
    MicropPython的学习,如何从0到1?
    MicroPython最全资料免费获取
    MicroPython技术及应用前景
    如何将AD原理图直接转为Orcad原理图
    USB音频声卡的时钟同步方式----同步、异步、自适应
    字符串指针数组长度
    关于传统模拟电话按键时间
    小米笔记本13.3寸 八代i5独显 记录
    小米笔记本Air 13.3 熄屏 大概率无法唤醒问题(已解决)
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/15559768.html
Copyright © 2011-2022 走看看