How to access FaceID for new iPhone X?

Viewed 6131

iPhone X is coming out with introduced FaceID to unlock phone and make Apple Pay.

Can we access the API?

I know last time we have to wait until TouchID release to developer.

Is there any dateline when perhaps?

5 Answers

Xcode 9.0.1 and 9.1 beta (9B37) have working support for Face ID.

APIs did not work in Xcode 9.0 GM.

AND, there is a bug that affects iOS 11.0.0 (the very first public version of iOS 11) which will cause the biometryType function to crash. Therefore, you must use this check:

if #available(iOS 11.0.1, *) {...}

AND, Apple changed the LABiometryType enum names in Xcode 9.2.

Swift 4

enum BioType {
case kFace
case kTouch
case kNone
}

func checkForBiometry() -> BioType {
    let context = LAContext()

               if #available(iOS 11.0, *),context.responds(to: #selector(getter: LAContext.biometryType))  {
            if context.biometryType == .typeFaceID {

                return .kFace
        }
        return .kTouch
    }
    return .kNone
 }
}

Edit:

Added responds(to: #selector) check as the app crashes with -[LAContext biometryType]: unrecognized selector on iOS 11.0.0 only devices.

I can confirm that there's a bug in the simulator for Xcode 9.

If I use Xcode 9.1 beta, This code works:

let authenticationContext = LAContext()
var error: NSError? = nil

if #available(iOS 11.0, *) {
    if authenticationContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error) {
        let bioType = authenticationContext.biometryType
        if bioType == .typeFaceID {
            touchIDButton.setImage(UIImage(named:"FaceIDLogo"), for: UIControlState.normal)
            touchIDButton.setImage(UIImage(named:"FaceIDLogo-Highlight"), for: UIControlState.highlighted)
        }
    }
}

I should note that it's important to run LAContext.canEvaluatePolicy before checking the biometric type.

Related