Using Touch ID API with iOS Swift

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.

Using Touch ID API with iOS Swift
Using Touch ID API with iOS Swift

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.

If the security policy cannot be evaluated then show a short message depending on the error. Which can be managed by this.

At the end add a method for showing alerts.

Now run your project. I guess you already did that 😉

First you will see screen like this.Using Touch ID API with iOS Swift


If the finger is not registered then the below error will shown.

Using Touch ID API with iOS Swift


If user select enter to enter password manually. Then the user will see the below screen.

Using Touch ID API with iOS Swift


So we handled all the possible conditions. You can modify them according to your requirement.


Today topic was Using Touch ID API with iOS Swift next time we will come with something more exciting. happy Coding 😉

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.