From 71abaec481425ddbf97e2d66e2bd4932daa24979 Mon Sep 17 00:00:00 2001 From: Yanko Dimitrov Date: Thu, 10 Sep 2015 10:50:21 +0300 Subject: [PATCH] Fixed the request for TouchID authentication --- PasscodeLock/PasscodeLock/PasscodeLock.swift | 4 ---- PasscodeLock/PasscodeLockViewController.swift | 18 +++++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/PasscodeLock/PasscodeLock/PasscodeLock.swift b/PasscodeLock/PasscodeLock/PasscodeLock.swift index a7446452..94ad33ac 100644 --- a/PasscodeLock/PasscodeLock/PasscodeLock.swift +++ b/PasscodeLock/PasscodeLock/PasscodeLock.swift @@ -84,10 +84,6 @@ public class PasscodeLock: PasscodeLockType { if success { self.delegate?.passcodeLockDidSucceed(self) - - } else { - - self.delegate?.passcodeLockDidFail(self) } } } diff --git a/PasscodeLock/PasscodeLockViewController.swift b/PasscodeLock/PasscodeLockViewController.swift index 43ca537e..969537d9 100644 --- a/PasscodeLock/PasscodeLockViewController.swift +++ b/PasscodeLock/PasscodeLockViewController.swift @@ -43,7 +43,7 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg internal let passcodeLock: PasscodeLockType internal var isPlaceholdersAnimationCompleted = true - private var shouldTryToAuthenticateWithBiometrics = false + private var shouldTryToAuthenticateWithBiometrics = true // MARK: - Initializers @@ -89,8 +89,10 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg public override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) - shouldTryToAuthenticateWithBiometrics = false - authenticateWithBiometrics() + if shouldTryToAuthenticateWithBiometrics { + + authenticateWithBiometrics() + } } internal func updatePasscodeView() { @@ -105,26 +107,24 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg private func setupEvents() { - notificationCenter?.addObserver(self, selector: "appDidBecomeActiveHandler:", name: UIApplicationDidBecomeActiveNotification, object: nil) + notificationCenter?.addObserver(self, selector: "appWillEnterForegroundHandler:", name: UIApplicationWillEnterForegroundNotification, object: nil) notificationCenter?.addObserver(self, selector: "appDidEnterBackgroundHandler:", name: UIApplicationDidEnterBackgroundNotification, object: nil) } private func clearEvents() { - notificationCenter?.removeObserver(self, name: UIApplicationDidBecomeActiveNotification, object: nil) + notificationCenter?.removeObserver(self, name: UIApplicationWillEnterForegroundNotification, object: nil) notificationCenter?.removeObserver(self, name: UIApplicationDidEnterBackgroundNotification, object: nil) } - public func appDidBecomeActiveHandler(notification: NSNotification) { - - guard shouldTryToAuthenticateWithBiometrics else { return } + public func appWillEnterForegroundHandler(notification: NSNotification) { authenticateWithBiometrics() } public func appDidEnterBackgroundHandler(notification: NSNotification) { - shouldTryToAuthenticateWithBiometrics = true + shouldTryToAuthenticateWithBiometrics = false } // MARK: - Actions