Monday, May 14, 2018

Biometric authentication - Face/Touch ID

Face/Touch Id Authentication integration into the app.

The code demonstrates how to integrate Face Id authentication integration into the app. Face Id is currently supported on iPhone X. This Code also works for touchId authentication.

Class BiometricAuthentication in this project is responsible for biometeric authentication and notify the success / fail status by posting Notifications

How to use BiometricAuthentication class?
Create an instance of BiometricAuthentication class
Call authenticationWithBiometricID to initiate the authentication process
Add notification observerers as below:
NotificationCenter.default.addObserver(self, selector: #selector(LoginVC.authenticationCompletionHandler(loginStatusNotification:)), name: .BiometricAuthenticationNotificationLoginStatus, object: nil)

Typecast userInfo[BiometricAuthentication.status] to BiometricAuthenticationStatus instance (authStatus) that holds the response object. a) check if authStatus.success is true for successfull authentication b) if authStatus.success is false, check for authStatus.errorMessage for error message and authStatus.errorCode for LAError code. Currently all the possible error codes are mapped to error message in the response.

A sample project can be found at github.