diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2020-02-26 15:08:21 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2020-02-26 17:19:33 +0100 |
| commit | b93b52ddf61925702cbca0c21991b30de8bf12f1 (patch) | |
| tree | 5012091ccee9a73afa7c189591001ca70b35d0ab /ios | |
| parent | a8516854256e0d0ea83bffd8568e86219852b9d1 (diff) | |
| download | mullvadvpn-b93b52ddf61925702cbca0c21991b30de8bf12f1.tar.xz mullvadvpn-b93b52ddf61925702cbca0c21991b30de8bf12f1.zip | |
Wire up consent view
Diffstat (limited to 'ios')
| -rw-r--r-- | ios/MullvadVPN/AppDelegate.swift | 38 | ||||
| -rw-r--r-- | ios/MullvadVPN/ConsentViewController.swift | 6 |
2 files changed, 35 insertions, 9 deletions
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift index 84e0fd7f81..663911f877 100644 --- a/ios/MullvadVPN/AppDelegate.swift +++ b/ios/MullvadVPN/AppDelegate.swift @@ -39,24 +39,44 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let rootViewController = self.mainStoryboard.instantiateViewController(identifier: ViewControllerIdentifier.root.rawValue) as! RootContainerViewController - let loginViewController = self.mainStoryboard.instantiateViewController(withIdentifier: ViewControllerIdentifier.login.rawValue) + if Account.shared.isAgreedToTermsOfService { + self.showMainController(in: rootViewController, animated: false) + } else { + self.showTermsOfService(in: rootViewController) { + Account.shared.agreeToTermsOfService() - var viewControllers = [loginViewController] - - if accountToken != nil { - let mainViewController = self.mainStoryboard.instantiateViewController(withIdentifier: ViewControllerIdentifier.main.rawValue) - - viewControllers.append(mainViewController) + self.showMainController(in: rootViewController, animated: true) + } } - rootViewController.setViewControllers(viewControllers, animated: false) - self.window?.rootViewController = rootViewController }) return true } + private func showTermsOfService(in rootViewController: RootContainerViewController, completionHandler: @escaping () -> Void) { + let consentViewController = self.mainStoryboard.instantiateViewController(withIdentifier: ViewControllerIdentifier.consent.rawValue) as! ConsentViewController + + consentViewController.completionHandler = completionHandler + + rootViewController.setViewControllers([consentViewController], animated: false) + } + + private func showMainController(in rootViewController: RootContainerViewController, animated: Bool) { + let loginViewController = self.mainStoryboard.instantiateViewController(withIdentifier: ViewControllerIdentifier.login.rawValue) + + var viewControllers = [loginViewController] + + if Account.shared.isLoggedIn { + let mainViewController = self.mainStoryboard.instantiateViewController(withIdentifier: ViewControllerIdentifier.main.rawValue) + + viewControllers.append(mainViewController) + } + + rootViewController.setViewControllers(viewControllers, animated: animated) + } + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. diff --git a/ios/MullvadVPN/ConsentViewController.swift b/ios/MullvadVPN/ConsentViewController.swift index d98619a9dc..28f27c976e 100644 --- a/ios/MullvadVPN/ConsentViewController.swift +++ b/ios/MullvadVPN/ConsentViewController.swift @@ -13,6 +13,8 @@ let kPrivacyPolicyURL = URL(string: "https://mullvad.net/en/help/privacy-policy/ class ConsentViewController: UIViewController, RootContainment, SFSafariViewControllerDelegate { + var completionHandler: (() -> Void)? + override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } @@ -34,6 +36,10 @@ class ConsentViewController: UIViewController, RootContainment, SFSafariViewCont present(safariController, animated: true) } + @IBAction func handleAgreeAndContinueButton(_ sender: Any) { + completionHandler?() + } + // MARK: - SFSafariViewControllerDelegate func safariViewControllerDidFinish(_ controller: SFSafariViewController) { |
