From b72895bbcfda0ae28bf28ed10531aa40566eb2ac Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Sun, 22 Apr 2018 23:37:46 +0800 Subject: [PATCH 1/2] Attempt to fix crash with iPhone X when device left to lock up when app is active and Face ID enabled in the app settings --- .../LockEnterPasscodeCoordinator.swift | 16 +++++++-------- .../Coordinators/ProtectionCoordinator.swift | 20 ++++++++----------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift b/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift index 4580c6b73..ab6e00e06 100644 --- a/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift +++ b/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift @@ -5,7 +5,6 @@ import UIKit class LockEnterPasscodeCoordinator: Coordinator { var coordinators: [Coordinator] = [] - var protectionWasShown = false private let window: UIWindow = UIWindow() private let model: LockEnterPasscodeViewModel private let lock: LockInterface @@ -20,21 +19,20 @@ class LockEnterPasscodeCoordinator: Coordinator { if state { self?.stop() } - self?.protectionWasShown = bioUnlock } } func start() { - guard lock.isPasscodeSet() else { - return - } - protectionWasShown = true + guard lock.isPasscodeSet() else { return } window.rootViewController = lockEnterPasscodeViewController window.makeKeyAndVisible() - //Because of the usage of the window and rootViewController we are not able to receive properly view life circle events. So we should call this methods manually. - lockEnterPasscodeViewController.showKeyboard() - lockEnterPasscodeViewController.showBioMerickAuth() } func stop() { window.isHidden = true } + + func showAuthentication() { + guard lock.isPasscodeSet() else { return } + lockEnterPasscodeViewController.showKeyboard() + lockEnterPasscodeViewController.showBioMerickAuth() + } } diff --git a/Trust/Protection/Coordinators/ProtectionCoordinator.swift b/Trust/Protection/Coordinators/ProtectionCoordinator.swift index 6219d3026..56ecf84ef 100644 --- a/Trust/Protection/Coordinators/ProtectionCoordinator.swift +++ b/Trust/Protection/Coordinators/ProtectionCoordinator.swift @@ -19,29 +19,25 @@ class ProtectionCoordinator: Coordinator { func didFinishLaunchingWithOptions() { splashCoordinator.start() lockEnterPasscodeCoordinator.start() - } - - func applicationWillResignActive() { - splashCoordinator.start() + lockEnterPasscodeCoordinator.showAuthentication() } func applicationDidBecomeActive() { - //We track protectionWasShown because of the Touch ID that will trigger applicationDidBecomeActive method after valdiation. - if !lockEnterPasscodeCoordinator.protectionWasShown { - lockEnterPasscodeCoordinator.start() - } else { - lockEnterPasscodeCoordinator.protectionWasShown = false - } - - //We should dismiss spalsh screen when app become active. splashCoordinator.stop() } + func applicationWillResignActive() { + splashCoordinator.start() + } + func applicationDidEnterBackground() { splashCoordinator.start() + lockEnterPasscodeCoordinator.start() } func applicationWillEnterForeground() { splashCoordinator.stop() + lockEnterPasscodeCoordinator.start() + lockEnterPasscodeCoordinator.showAuthentication() } } From 67202dd0021d2a2286ae4d49d7bda7ef7a28d035 Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Wed, 25 Apr 2018 15:57:55 +0800 Subject: [PATCH 2/2] Fix test for protection --- .../Coordinators/LockEnterPasscodeCoordinator.swift | 2 +- .../LockEnterPasscodeCoordinatorTest.swift | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift b/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift index ab6e00e06..fa0afe386 100644 --- a/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift +++ b/Trust/Protection/Coordinators/LockEnterPasscodeCoordinator.swift @@ -5,7 +5,7 @@ import UIKit class LockEnterPasscodeCoordinator: Coordinator { var coordinators: [Coordinator] = [] - private let window: UIWindow = UIWindow() + let window: UIWindow = UIWindow() private let model: LockEnterPasscodeViewModel private let lock: LockInterface private lazy var lockEnterPasscodeViewController: LockEnterPasscodeViewController = { diff --git a/TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift b/TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift index 38fe5db85..6aab28c78 100644 --- a/TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift +++ b/TrustTests/Coordinators/LockEnterPasscodeCoordinatorTest.swift @@ -8,26 +8,26 @@ class LockEnterPasscodeCoordinatorTest: XCTestCase { let viewModel = LockEnterPasscodeViewModel() let fakeLock = FakeLockProtocol() let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) - XCTAssertFalse(coordinator.protectionWasShown) + XCTAssertTrue(coordinator.window.isHidden) coordinator.start() - XCTAssertTrue(coordinator.protectionWasShown) + XCTAssertFalse(coordinator.window.isHidden) } func testStop() { let viewModel = LockEnterPasscodeViewModel() let fakeLock = FakeLockProtocol() let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) - XCTAssertFalse(coordinator.protectionWasShown) coordinator.start() - XCTAssertTrue(coordinator.protectionWasShown) + XCTAssertFalse(coordinator.window.isHidden) coordinator.stop() + XCTAssertTrue(coordinator.window.isHidden) } func testDisableLock() { let viewModel = LockEnterPasscodeViewModel() let fakeLock = FakeLockProtocol() fakeLock.passcodeSet = false let coordinator = LockEnterPasscodeCoordinator(model: viewModel, lock: fakeLock) - XCTAssertFalse(coordinator.protectionWasShown) + XCTAssertTrue(coordinator.window.isHidden) coordinator.start() - XCTAssertFalse(coordinator.protectionWasShown) + XCTAssertTrue(coordinator.window.isHidden) } }