Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Data and cache wkwebview swift 4

I am using a wkwebview to display a URL, I need the site data and cache to deleted or not to save cache at all. I need it to load up a fresh page each time. I have tried several methods but none work.

@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var searchBar: UISearchBar!

override func viewDidLoad() {
    super.viewDidLoad()

    searchBar.backgroundImage = UIImage() // removes border

    let myURL = URL(string: "https://myURL.com")!
    let myRequest = URLRequest(url: myURL)
    webView.load(myRequest)

}

}

like image 565
Joshua Quilliam Avatar asked Oct 24 '25 19:10

Joshua Quilliam


1 Answers

If you don't ever want caching try setting the NSURLRequest.CachePolicy to reloadIgnoringLocalAndRemoteCacheData when initialising the URLRequest.

e.g.

let request = URLRequest(url: myURL, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 10)
like image 99
Gary M Avatar answered Oct 26 '25 07:10

Gary M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!