Language/iOS,AOS

웹뷰 캐시 삭제

건담아빠 2023. 3. 1. 17:35

 

iOS에서 usb로 단말기를 연결 한 후 웹뷰를 띄우니고 테스트를 하던중에.. js, css변경을 해도 적용이 안된다..

아놔.. 그래서 찾아봤다!! 진작에 찾아볼걸..!

 

 

Utils.swift

class Utils: NSObject {
    ...
    
    public static func CoreURLRequest(url: URL) -> URLRequest {
        var urlRequest: URLRequest
        
        if (self.isDebug() == true) {
            urlRequest = URLRequest(url: url,
                                    cachePolicy:NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData,
                                    timeoutInterval: 10.0)
        }
        else {
            urlRequest = URLRequest(url: url)
        }
        
        return urlRequest;
    }
    
    ...
}

 

사용한 코드

wKWindowFull?.load(Utils.CoreURLRequest(url: webUrl))

 

 

필자는 아래코드 안 넣어도 잘된다!!

하지만 구글링 상에서는 아래 코드도 캐시와 관련이 있다는거 같아서 혹시나 모르니 정리둔다.

URLCache.shared.removeAllCachedResponses()
URLCache.shared.diskCapacity = 0
URLCache.shared.memoryCapacity = 0

 

 

 

참고

https://stackoverflow.com/questions/28107806/clearing-uiwebviews-cache-in-swift

 

Clearing UIWebView's Cache in Swift

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. So is there any code I can do this in Sw...

stackoverflow.com