yankodimitrov / SwiftPasscodeLock

An iOS passcode lock with TouchID authentication written in Swift.
MIT License
681 stars 263 forks source link

[Question] How to "kill" the PasscodeViewController #50

Closed le4ker closed 8 years ago

le4ker commented 8 years ago

First of all, great stuff!

Second, I have the scenario where a user reaches the max number of passcode attempts. When this happens, I want to delete all the sensitive information of the app and destroy the PasscodeViewController.

How can I do the latter?

Thanks! :panos

antonigiske commented 8 years ago

@PanosSakkos You have to add an observer for the notification. The documentation is a little misguiding and providing wrong name.

You can put this in your first root controller's viewDidLoad. NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(logoutApp(_:)), name: "passcode.lock.incorrect.passcode.notification", object: nil)

Then you have to implement the logoutApp function. This is just an example.

func logoutApp(notification: NSNotification) {

        // Destroy sensitive stuff.

        let delegate = UIApplication.sharedApplication().delegate as! AppDelegate

        self.presentedViewController?.dismissViewControllerAnimated(false, completion: {
            delegate.passcodeLockPresenter.dismissPasscodeLock(animated: true)
        })
}
le4ker commented 8 years ago

@antonigiske thanks for the reply!

For some reason the dismissPasscodeLock method is private in my PasscodeLockPresenter. I checked the repo here and the source code is different, with this method offered as public.

I did a carthage update but I still don't have the latest source code

Any ideas?

Thanks! :panos

antonigiske commented 8 years ago

@PanosSakkos I don't know. I used CocoaPods, and its public with me.

le4ker commented 8 years ago

Got it from CocoaPods and it worked, thanks! 👍