How to clear UIWebView cache?

前端 未结 9 1731
闹比i
闹比i 2020-11-29 04:47

I need UIWebView to display some local .webarchive file. But images there have same names, so UIWebView shows only one image all the time. How can I clear the cache?

相关标签:
9条回答
  • 2020-11-29 05:25

    For swift 3

    //to remove cache from UIWebview
    URLCache.shared.removeAllCachedResponses()
        if let cookies = HTTPCookieStorage.shared.cookies {
            for cookie in cookies {
                HTTPCookieStorage.shared.deleteCookie(cookie)
            }
        }
    
    0 讨论(0)
  • 2020-11-29 05:28
    // Flush all cached data
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    
    0 讨论(0)
  • 2020-11-29 05:28
    NSURLRequest* request = [NSURLRequest requestWithURL:fileURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
    
    [webView loadRequest:request];
    

    (now with typo fixed)

    0 讨论(0)
提交回复
热议问题