iOS webview清除缓存

来源:互联网 发布:股票分时预警软件 编辑:程序博客网 时间:2024/05/29 14:28

使用ios的webview会自动进行缓存,我们在开发的时候要记得清除Cookie和缓存。

在webview的关闭按钮中添加两个方法

/**webView退出方法*/- (void)closeBtnAction:(UIButton *)button{     _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];}


2 0