How to access FaceID for new iPhone X?

ios iphone-x

5709 观看


10487 作者的声誉

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?

作者: HelmiB 的来源 发布者: 2017 年 9 月 15 日

回应 5


82353 作者的声誉


It's actually already available in Xcode 9 in the same place TouchID functionality is found. Look at LocalAuthentication -> LAContext -> LABiometryType for example.

If you look at the documentation at a higher level, LAContext, the new API's can be currently found with a "Beta" label on them (presumably these will be removed as soon as Xcode 9 & iOS 11 are officially released).

作者: Michael Dautermann 发布者: 2017 年 9 月 15 日


107461 作者的声誉

There are a comment and an answer here that each tell only part of the story, so let’s bring them together:

As noted by @Paulw11 in comments, the APIs for authenticating with Touch ID — LAContext canEvaluatePolicy to check for availability, evaluatePolicy to actually request authentication — work just the same for Face ID. You might notice that all of those APIs never actually mention Touch ID, just “biometrics” in the abstract... it’s almost as if Apple was thinking ahead when they released that API back in iOS 8.

Apple’s Craig Federighi confirmed this in a recent appearance on The Talk Show podcast. He says that he and other Apple employees carrying iPhone X have been running existing apps — bank apps, airline apps, etc — that use these APIs, and they “just work” with Face ID. The same API call just automatically invokes the new UI, except it’s usually faster because the user is probably already looking at the phone so they don’t have to do anything.

Now, as @MichaelDautermann’s answer notes, there are also new APIs for distinguishing Touch ID from Face ID: LAContext biometryType tells you which kind of biometrics the current device supports.

If the same APIs work for invoking both Touch ID and Face ID, why also the new thing? It’s so your app can talk about it in your UI. Think about all the bank and credit card and password manager and whatnot apps you’ve ever used — you log in to that app with a password, then afterward it asks you if you want to use Touch ID instead of your password next time. All of that is custom UI from those apps’ developers, so they’ll need to use this new API so their UI can correctly say “use Touch ID” or “use Face ID” depending on the current device.

作者: rickster 发布者: 2017 年 9 月 17 日


6895 作者的声誉

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.

作者: Daniel 发布者: 2017 年 9 月 29 日


2284 作者的声誉

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.

作者: Chris Marshall 发布者: 2017 年 10 月 26 日


810 作者的声誉

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


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

作者: Sonu VR 发布者: 2017 年 11 月 3 日