Look Mom! No Hands.
One of the coolest things about the iPhone X is using Face ID without touching the screen. You added a button which you can use to trigger the Face ID, but you can trigger Face ID automagically as well.
Open LoginViewController.swift and add the following code right below viewDidLoad()
:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let touchBool = touchMe.canEvaluatePolicy()
if touchBool {
touchIDLoginAction()
}
}
The above will verify if biometric ID is supported and if so try and authenticate the user.
Build and run on an iPhone X or Face ID equipped device and test logging in hands free!
Where to Go from Here?
You can download the completed sample application from this tutorial here.
The LoginViewController
you’ve created in this tutorial provides a jumping-off point for any app that needs to manage user credentials.
You can also add a new view controller, or modify the existing LoginViewController
, to allow the user to change the password from time to time. This isn’t necessary with biometric ID, since the user’s biometrics probably won’t change much in their lifetime! :] However, you could create a way to update the Keychain; you’d want to prompt the user for their current password before accepting their modification.
Apple also recommends hiding the username and password fields and login button when using Face ID. I’ll leave that for you as a simple challenge.
You can read more about securing your iOS apps in Apple’s official iOS Security Guide.
As always, if you have any questions or comments on this tutorial, feel free to join the discussion below!