Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Touch ID - How to get to the passcode screen? -Swift

So I have been searching all over stackoverflow and I cannot seen to find the answer for this. How do I allow a user to access the built in apple passcode screen when a user taps "Enter Password"? Please click the link provided below to see an image illustrations this issue. Thanks for the help and please write it in Swift!

http://i.stack.imgur.com/id9E3.jpg

like image 393
JakeC Avatar asked Dec 09 '15 17:12

JakeC


1 Answers

This can be done with iOS 9, which exposes a new LAPolicy type, i.e. when calling evaluatePolicy, pass in DeviceOwnerAuthentication and not DeviceOwnerAuthenticationWithBiometrics.

Here's some swift:

import LocalAuthentication

function authenticateUser() {
    let context = LAContext()

    context.evaluatePolicy(LAPolicy.DeviceOwnerAuthentication, localizedReason: "Please authenticate to proceed.") { [weak self] (success, error) in

        guard success else {
            dispatch_async(dispatch_get_main_queue()) {
                // show something here to block the user from continuing
            }

            return
        }

        dispatch_async(dispatch_get_main_queue()) {
            // do something here to continue loading your app, e.g. call a delegate method
        }
    }
}

Now, when the user taps the home button with the wrong finger, the alert box will show an "Enter Passcode" option:

enter image description here

Tapping on Enter Passcode will show one of two prompts depending on whether the user has a numeric or alphanumeric passcode set:

Numeric passcode:

numeric passcode

Alphanumeric passcode:

alphanumeric passcode

like image 111
parag Avatar answered Oct 16 '22 06:10

parag