Quellcode durchsuchen

Trigger refresh when changing url and url verification improvement

Jonas Björkert vor 2 Jahren
Ursprung
Commit
1a440efafd

+ 6 - 0
LoopFollow/ViewControllers/MainViewController.swift

@@ -258,6 +258,12 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         refreshScrollView.alwaysBounceVertical = true
         
         refreshScrollView.delegate = self
+        
+        NotificationCenter.default.addObserver(self, selector: #selector(refresh), name: NSNotification.Name("refresh"), object: nil)
+    }
+    
+    deinit {
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name("refresh"), object: nil)
     }
     
     // Clean all timers and start new ones when refreshing

+ 1 - 0
LoopFollow/ViewControllers/SettingsViewController.swift

@@ -282,6 +282,7 @@ class SettingsViewController: FormViewController {
             }
         } else {
             statusLabelRow.value = "OK"
+            NotificationCenter.default.post(name: NSNotification.Name("refresh"), object: nil)
         }
         statusLabelRow.updateCell()
     }

+ 6 - 2
LoopFollow/helpers/NightscoutUtils.swift

@@ -111,7 +111,6 @@ class NightscoutUtils {
         task.resume()
     }
     
-    @available(*, deprecated, message: "Use constructURL instead.")
     static func createURLRequest(url: String, token: String?, path: String) -> URLRequest? {
         var requestURLString = "\(url)\(path)"
         
@@ -153,7 +152,12 @@ class NightscoutUtils {
             completion(.emptyAddress)
             return
         }
-
+        
+        guard let _ = URL(string: urlUser), urlUser.hasPrefix("http://") || urlUser.hasPrefix("https://") else {
+            completion(.invalidURL)
+            return
+        }
+        
         guard let request = createURLRequest(url: urlUser, token: token, path: "/api/v1/status") else {
             completion(.invalidURL)
             return