Просмотр исходного кода

Add yes/no alert (DO you want to clear cache) when refreshing NS webview

dsnallfot 2 лет назад
Родитель
Сommit
16f2d41a3a
1 измененных файлов с 15 добавлено и 4 удалено
  1. 15 4
      LoopFollow/ViewControllers/NightScoutViewController.swift

+ 15 - 4
LoopFollow/ViewControllers/NightScoutViewController.swift

@@ -45,12 +45,23 @@ class NightscoutViewController: UIViewController {
     }
     
     @objc func reloadWebView(_ sender: UIRefreshControl) {
-        clearWebCache() // Clear web cache when reloading page by swiping down
-        webView.reload()
-        sender.endRefreshing()
+        let alertController = UIAlertController(title: "Clear Web Cache", message: "Do you want to clear the web cache?\nNote: All Nightscout settings will be reverted to defaults!", preferredStyle: .alert)
+        
+        alertController.addAction(UIAlertAction(title: "Yes", style: .destructive) { _ in
+            self.clearWebCache()
+            self.webView.reload()
+            sender.endRefreshing()
+        })
+        
+        alertController.addAction(UIAlertAction(title: "No", style: .cancel) { _ in
+            self.webView.reload()
+            sender.endRefreshing()
+        })
+        
+        present(alertController, animated: true, completion: nil)
     }
     
-    // New code to Clear web cache
+    // New code to clear web cache
     func clearWebCache() {
         let dataStore = WKWebsiteDataStore.default()
         let date = Date(timeIntervalSince1970: 0)