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];
        }
    
  • 相关阅读:
    BZOJ2243: [SDOI2011]染色(树链剖分/LCT)
    BZOJ2157: 旅游(LCT)
    BZOJ3510首都(LCT)
    BZOJ4530 [BJOI2014]大融合(LCT)
    BZOJ2631: tree(LCT)
    BZOJ2002: [Hnoi2010]Bounce 弹飞绵羊(LCT)
    BZOJ3282: Tree (LCT模板)
    [NOI2008]假面舞会(DFS)
    斜率优化dp练习
    BZOJ2049[Sdoi2008]Cave 洞穴勘测(LCT模板)
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/15559768.html
Copyright © 2011-2022 走看看