Clearing UIWebView's Cache in Swift

后端 未结 5 1576
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 03:45

I have a UIWebView inside my app. This UIWebView needs to be reloaded fully (i.e. clear all cache of images/HTML/cookies etc.) every time when viewDidLoad.

5条回答
  •  甜味超标
    2020-12-30 04:04

    Swift 3.

    URLCache.shared.removeAllCachedResponses()
    URLCache.shared.diskCapacity = 0
    URLCache.shared.memoryCapacity = 0
    
    if let cookies = HTTPCookieStorage.shared.cookies { 
        for cookie in cookies {
            HTTPCookieStorage.shared.deleteCookie(cookie)
        }
    }
    

提交回复
热议问题