清除WebView缓存和cookie

首先添加一个按钮,点击它的时候执行清缓存和cookie操作,这里我重写了导航的返回按钮:

-(void)leftBarButtonClicked{
    _webView = nil;
    [self cleanCacheAndCookie];
    [self.navigationController popViewControllerAnimated:YES];
}

/**清除缓存和cookie*/
- (void)cleanCacheAndCookie{
    //清除cookies
    NSHTTPCookie *cookie;
    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (cookie in [storage cookies]){
        [storage deleteCookie:cookie];
    }
    //清除UIWebView的缓存
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    NSURLCache * cache = [NSURLCache sharedURLCache];
    [cache removeAllCachedResponses];
    [cache setDiskCapacity:0];
    [cache setMemoryCapacity:0];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,802评论 25 709
  • HTTP cookie(也称为web cookie,网络cookie,浏览器cookie或者简称cookie)是网...
    留七七阅读 18,166评论 2 71
  • 引子 一粒明亮的光点抗拒着地心引力升到空中。 它不见了。 它没有消失,它绽放了。 原本漆黑一团的夜空,在那一刹明亮...
    亚洲图片阅读 737评论 0 1
  • 与影对话 笑桃花 三生石畔 清清浅浅 流光的周转 扶起萍叶寒星 悠悠然…… 似是而非的脸 是彩霞模仿三分 星云摇曳...
    清面如歌阅读 136评论 2 3
  • 今天我和妈妈早早就起来了,因为要坐火车,去我姥姥家,我姥姥家在哈尔滨。我们先坐滴滴顺风车到了淄博高铁站。然后...
    山药粉阅读 199评论 1 1