Skip to content

Commit 1bf6119

Browse files
authored
Merge pull request #260 from dsnallfot/dev_clear_ns_cache
Add function to clear web cache (Nightscout) when refreshing view by swiping down
2 parents 13a566c + 652470c commit 1bf6119

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

LoopFollow/ViewControllers/NightScoutViewController.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,23 @@ class NightscoutViewController: UIViewController {
4343

4444
self.webView.uiDelegate = self
4545
}
46-
46+
4747
@objc func reloadWebView(_ sender: UIRefreshControl) {
48-
webView.reload()
48+
self.clearWebCache()
49+
self.webView.reload()
4950
sender.endRefreshing()
5051
}
5152

53+
// New code to clear web cache
54+
func clearWebCache() {
55+
let dataStore = WKWebsiteDataStore.default()
56+
let cacheTypes = Set([WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache])
57+
let date = Date(timeIntervalSince1970: 0)
58+
dataStore.removeData(ofTypes: cacheTypes, modifiedSince: date) {
59+
print("Web cache cleared.")
60+
}
61+
}
62+
5263
// this handles target=_blank links by opening them in the same view
5364
func webView(webView: WKWebView!, createWebViewWithConfiguration configuration: WKWebViewConfiguration!, forNavigationAction navigationAction: WKNavigationAction!, windowFeatures: WKWindowFeatures!) -> WKWebView! {
5465
if let frame = navigationAction.targetFrame,

0 commit comments

Comments
 (0)