iOS - Face ID生物识别集成

Kru*_*nal 7 ios touch-id swift ios11 face-id

我已经为我的应用程序集成/实现了面部识别(本地身份验证)身份验证,除了面部识别提示警报窗口界面外,每件事情都运行良好.

它显示了一个圆角正方形,浅灰色背景和标题"面部ID".

应该为标题上方的空白区域设置什么.这是脸部ID图标的空间吗?如果是,那我该怎么设置呢?我已经尝试了LAContext和LAPolicy中的所有内容.

看看这个快照:

在此输入图像描述

这是我的代码:

    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")
                    }
                }

            })
        })
    }
Run Code Online (Sandbox Code Playgroud)

Daz*_*ong 15

这只发生在模拟器中,在实际设备中画布被面部图标动画占据.

localizedReason仅适用于Touch ID,因为它们共享相同的API.

更新1:添加了屏幕录制:

他们都运行相同的代码:

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")
    }

}
Run Code Online (Sandbox Code Playgroud)

这是TouchID和FaceID的工作代码,包含所有错误代码(Swift 4)

/sf/answers/3646548601/