The topic of this tutorial Using Touch ID API with iOS Swift. TouchID, the biometric authentication technology, Apple introduced it in iOS 7 and used in iPhone 5s. It allow users to unlock their devices and user can also make purchases on the App Store. From iOS 8 and above we can add TouchID as an authentication mechanism into our applications, and it is very fast and easy to use.
For implementing TouchID import Local Authentication Framework into our app.
Lets create a new method for authenticating user. Also import LocalAuthentication into ViewController.swift file.
First get the local authentication context. Then declare a NSError variable. After that evaluate policy.
If the authentication failed then we can show a message to the console with a short description. In case that the error is a user fallback, then show the password alert view. We can handle that error and show alert as below in the else condition containing a switch statement for different errors.
print("Authentication was cancelled by the system")