Prechádzať zdrojové kódy

Clear app browser cache when refreshing Nightscout view by swiping down
- All changed settings reverts to default NS config vars
- Any changes made in nightscout code is imediately visible after reloaded (dont need to wait for ios to purge cache or reinstall loop follow to see changes)

dsnallfot 2 rokov pred
rodič
commit
70d2979433

+ 11 - 1
LoopFollow/ViewControllers/NightScoutViewController.swift

@@ -43,12 +43,22 @@ class NightscoutViewController: UIViewController {
         
         self.webView.uiDelegate = self
     }
-
+    
     @objc func reloadWebView(_ sender: UIRefreshControl) {
+        clearWebCache() // Clear web cache when reloading page by swiping down
         webView.reload()
         sender.endRefreshing()
     }
     
+    // New code to Clear web cache
+    func clearWebCache() {
+        let dataStore = WKWebsiteDataStore.default()
+        let date = Date(timeIntervalSince1970: 0)
+        dataStore.removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), 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,