In: Computer Science
The first step would be creating a new project under the file menu and then choose the Single View Application. Then, click on the next button.
In the next step, you need to name your project. For example, you can name it as Biometrics Authentication.
Upon the successful creation of the project, it’s time to import the Local Authentication in ViewController.swift.
One needs to go for the configuration of the Face ID privacy statement in the Info.plist file statement of the project.
This is the privacy statement, which a user sees when the app wants to take permission to use the Face ID authentication. For the addition of this privacy statement, first, choose the Info.plist file in the project navigator panel and click on the + button that is found at the bottom of the list entry.
Next is choosing the Privacy – Face ID Usage Description from the desired outcome of the previous program. Now, add the description into the desired field.
Then you need to check the biometric authentication availability first. This is applicable for both integrating the touch and face id.
Once you are confirmed, that it would support the Touch Id, you can go with the following command:
@IBAction func authenticateUser(_ sender: Any) {
// Device can use biometric authentication
if context.canEvaluatePolicy(
LAPolicy.deviceOwnerAuthenticationWithBiometrics,
error: &error) {
context.evaluatePolicy(
.deviceOwnerAuthenticationWithBiometrics,
localizedReason: self.strAlertMessage,
reply: { [unowned self] (success, error) -> Void in
DispatchQueue.main.async {
if( success ) {
//Fingerprint recognized
// Do whatever action you want to perform
} else {
//If not recognized then
if let error = error {
let strMessage = self.errorMessage(errorCode: error._code)
print(strMessage)
}
}
}
})
}
}
For face integration-
You can follow two methodologies here; the first is using the iOS devices manually where you get the biometric support. In the second process, you need to employ the simulator environment.
If you are opting for the second method to conduct the Face ID integration test, then the compilation and running the app on an iPhone X simulator becomes important.
When the app gets released, you need to choose the simulator’s hardware and then select the Face ID menu. However, it must be ensured that you have enabled the enrolled option. Now, tap on the authentication button in the app.