8

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!

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

JakeC
  • 231
  • 1
  • 2
  • 9
  • 1
    This isn't standard behavior, and you'll have to build the passcode input view/behavior yourself. – Jacob Relkin Dec 09 '15 at 17:28
  • @Jacob Relkin Currently I implemented Touch ID and when I purposely fail enough times to login with my fingerprint a white built in passcode screen pops up and I am able to enter my 4 digit passcode to get inside the app. Is there a way to make that pop up at will? – JakeC Dec 09 '15 at 17:40
  • 1
    you cannot access the apple passcode unlock screen .There is no api to do that. You need to design your own UI screen. – Teja Nandamuri Dec 09 '15 at 17:46
  • @Mr.T So when a user taps "Enter Passcode" how are they suppose to login in if their Touch ID isn't working at the moment( maybe they have stuff all over their fingers? In this tutorial I am doing the passcode pad eventually pops up by itself. Thanks btw – JakeC Dec 09 '15 at 17:49
  • 1
    you need to check for the case UserFallback,and present your login screen.When the user taps on enter password, the touch id api LAError returns the flag UserFallback. – Teja Nandamuri Dec 09 '15 at 17:55
  • 1
    @JakeC I understand what you are saying. Unfortunately there is no way to customize apple's dialog box to take a user to some other custom screen. – Sam B Dec 09 '15 at 18:00
  • @ Mr.T I have the UserFallback case enable but nothing happens besides the print statement i put there to make sure it was working. Can you please tell me the lines of code I would have to write to make the passcode pas pop up? Thanks – JakeC Dec 09 '15 at 18:04
  • @ Sam B I don't think I am trying to customize anything. All I would like is to enable the user to have a plan B to log in like the passcode pad.BTW I am new to programming so thanks for the help – JakeC Dec 09 '15 at 18:05
  • I'll chime in and agree with all the others who are saying this. You cannot bring that screen up. That is the "biometrics have failed" screen. Apple brings that up. You say you are not trying to customize anything. That's the problem. You need to customize. How will your users login without Touch ID? That's the function you call when Touch ID fails. – Paul Cezanne Dec 10 '15 at 13:20

1 Answers1

23

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

parag
  • 937
  • 13
  • 11