From fdba9f38159c44d51d785895dc13d1271b968e02 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 21 Oct 2019 00:30:49 +0200 Subject: [PATCH] Auto-trust Wi-Fi only when requesting access Delegate may invoked in other scenarios. Do nothing in that case. --- Passepartout-iOS/Scenes/ServiceViewController.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index d27660dd..dc93c9ea 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -42,6 +42,8 @@ class ServiceViewController: UIViewController, StrongTableHost { private let locationManager = CLLocationManager() + private var isPendingTrustedWiFi = false + private let downloader = FileDownloader( temporaryURL: GroupConstants.App.cachesURL.appendingPathComponent("downloaded.tmp"), timeout: AppConstants.Web.timeout @@ -349,6 +351,7 @@ class ServiceViewController: UIViewController, StrongTableHost { break case .denied: + isPendingTrustedWiFi = false let alert = UIAlertController.asAlert( L10n.App.Service.Cells.TrustedAddWifi.caption, L10n.App.Service.Alerts.Location.Message.denied @@ -361,6 +364,7 @@ class ServiceViewController: UIViewController, StrongTableHost { return default: + isPendingTrustedWiFi = true locationManager.delegate = self locationManager.requestWhenInUseAuthorization() return @@ -1327,8 +1331,10 @@ extension ServiceViewController: ProviderPresetViewControllerDelegate { extension ServiceViewController: CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { - - // can only change when calling this method, re-invoke + guard isPendingTrustedWiFi else { + return + } + isPendingTrustedWiFi = false trustCurrentWiFi() } }