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];
        }
    
  • 相关阅读:
    pycharm快捷键
    对迭代器操作的python 模块
    编译入门:传说中的编译是在做什么
    机器学习原理与算法(剧场版)机器学习中的最优化问题
    机器学习原理与算法(六) 支持向量机
    机器学习原理与算法(五) 生成学习算法
    机器学习原理与算法(四) 广义线性模型
    机器学习原理与算法(三) 监督学习之分类问题
    机器学习原理与算法(一) 机器学习概述
    Altera FPGA SoC搭建步骤
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/15559768.html
Copyright © 2011-2022 走看看