Improve interaction after changing location auth

- Auto-add Wi-Fi after granting location access
- Show alert when location access is denied

TODO: localize.
This commit is contained in:
Davide De Rosa 2019-10-21 00:17:25 +02:00
parent fbe7d776e7
commit 9b96707d5b
1 changed files with 18 additions and 2 deletions

View File

@ -349,12 +349,20 @@ class ServiceViewController: UIViewController, StrongTableHost {
break
case .denied:
// TODO: alert when location denied
let alert = UIAlertController.asAlert(
L10n.App.Service.Cells.TrustedAddWifi.caption,
"You must allow location access to trust this Wi-Fi network. Go to iOS settings and review your location permissions for Passepartout."
)
alert.addCancelAction(L10n.Core.Global.ok)
alert.addPreferredAction("Settings") {
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
}
present(alert, animated: true, completion: nil)
return false
default:
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
// TODO: auto-invoke trustCurrentWiFi() again when location granted
return false
}
}
@ -1318,6 +1326,14 @@ extension ServiceViewController: ProviderPresetViewControllerDelegate {
}
}
extension ServiceViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
// can only change when calling this method, re-invoke
_ = trustCurrentWiFi()
}
}
// MARK: -
private extension ServiceViewController {