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
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:
Tapping on Enter Passcode
will show one of two prompts depending on whether the user has a numeric or alphanumeric passcode set:
Numeric passcode:
Alphanumeric passcode:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With