Skip to content

Commit

Permalink
Merge pull request #260 from dsnallfot/dev_clear_ns_cache
Browse files Browse the repository at this point in the history
Add function to clear web cache (Nightscout) when refreshing view by swiping down
  • Loading branch information
marionbarker authored Mar 6, 2024
2 parents 13a566c + 652470c commit 1bf6119
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions LoopFollow/ViewControllers/NightScoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,23 @@ class NightscoutViewController: UIViewController {

self.webView.uiDelegate = self
}

@objc func reloadWebView(_ sender: UIRefreshControl) {
webView.reload()
self.clearWebCache()
self.webView.reload()
sender.endRefreshing()
}

// New code to clear web cache
func clearWebCache() {
let dataStore = WKWebsiteDataStore.default()
let cacheTypes = Set([WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache])
let date = Date(timeIntervalSince1970: 0)
dataStore.removeData(ofTypes: cacheTypes, modifiedSince: date) {
print("Web cache cleared.")
}
}

// this handles target=_blank links by opening them in the same view
func webView(webView: WKWebView!, createWebViewWithConfiguration configuration: WKWebViewConfiguration!, forNavigationAction navigationAction: WKNavigationAction!, windowFeatures: WKWindowFeatures!) -> WKWebView! {
if let frame = navigationAction.targetFrame,
Expand Down

0 comments on commit 1bf6119

Please sign in to comment.