iOS: Authenticating with TouchID
Hi guys!
Today we will learn how to use Touch ID authentication with Swift 3.
Let’s rock.
Step 1: create a new project and named it TouchIdDemo.
Step 2: on ViewController, create a method to call touch ID verification after view appear:
Step 3: Nice! Now, to use touch ID framework we must to import the LocalAuthentication framework.
Click on your project:
Scroll to bottom, go to Linked Frameworks and Libraries and import the framework:
Step 4: go to your ViewController and import the lib:
Step 5: in authenticateWithTouchId that we have created, create a context and check if touch ID is avaliable:
The errorPointer is a variable that contains the error description when touch ID is not available.
Step 6: create a method named requestTouchIdValidation and call int on authenticateWithTouchId:
Step 7: handle success authentication:
Step 8: handle error authentication
Important: the touch ID only works on physical device. Don’t try it on simulator.
Github Project: https://github.com/benhurott/ios-touch-id-demo