Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Face ID biometric integration

I've integrated/implemented Face ID (Local Authentication) authentication for my app and everything works fine, except Face ID prompt Alert window interface.

It shows, a rounded square with a light gray background and the title "Face ID".

What should need to set for blank area exact above title? Is that space for face id icon? if yes then how can I set it? I've tried everything in LAContext and LAPolicy.

Look at this snapshot:

enter image description here

Here is my code:

    let laContext = LAContext()
    var error: NSError?
    let biometricsPolicy = LAPolicy.deviceOwnerAuthenticationWithBiometrics

    if (laContext.canEvaluatePolicy(biometricsPolicy, error: &error)) {

        if let laError = error {
            print("laError - \(laError)")
            return
        }

        var localizedReason = "Unlock device"
        if #available(iOS 11.0, *) {
            switch laContext.biometryType {
            case .faceID: localizedReason = "Unlock using Face ID"; print("FaceId support")
            case .touchID: localizedReason = "Unlock using Touch ID"; print("TouchId support")
            case .none: print("No Biometric support")
            }
        } else {
            // Fallback on earlier versions
        }


        laContext.evaluatePolicy(biometricsPolicy, localizedReason: localizedReason, reply: { (isSuccess, error) in

            DispatchQueue.main.async(execute: {

                if let laError = error {
                    print("laError - \(laError)")
                } else {
                    if isSuccess {
                        print("sucess")
                    } else {
                        print("failure")
                    }
                }

            })
        })
    }
like image 908
Krunal Avatar asked Nov 08 '17 15:11

Krunal


People also ask

Is Apple Face ID biometric?

for the iPhone and iPad Pro. The system allows biometric authentication for unlocking a device, making payments, accessing sensitive data, providing detailed facial expression tracking for Animoji, as well as six degrees of freedom (6DOF) head-tracking, eye-tracking, and other features.

How are biometrics implemented in iOS?

Biometric authentication for iOS applications is implemented using the Local Authentication Framework. The key class within this framework is the LAContext class which, among other tasks, is used to evaluate the authentication abilities of the device on which the application is running and perform the authentication.

Which iPhone has both Face ID and Touch ID?

According to a new report from WSJ, the 2021 iPhones will be the first ones to come with both in-display TouchID and FaceID. If true, the iPhone 12s (or iPhone 13) would be the only smartphone to feature FaceID as well as an advanced in-screen fingerprint scanner, giving Apple an edge over several of its competitors.


1 Answers

That is only happen in simulator, in actual device the canvas is occupied by face icon animation.

The localizedReason is for only for Touch ID, since they both sharing the same API.

Update 1: Added screen recordings:

  • iPhone X: https://youtu.be/lklRnLNHyQk
  • iPhone 7: https://youtu.be/iIcduvD5JO0
  • iPhone X Simulator: https://youtu.be/bOlRVLIND5c

They all ran the same code:

func beginFaceID() {

    guard #available(iOS 8.0, *) else {
        return print("Not supported")
    }

    let context = LAContext()
    var error: NSError?

    guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
        return print(error)
    }

    let reason = "Face ID authentication"
    context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { isAuthorized, error in
        guard isAuthorized == true else {
            return print(error)
        }

        print("success")
    }

}

Here is Working code for both TouchID & FaceID with all Error Codes (Swift 4)

https://stackoverflow.com/a/52093551/10150796

like image 65
DazChong Avatar answered Oct 19 '22 05:10

DazChong