iOS-Face ID生物识别集成 [英] iOS - Face ID biometric integration

查看:95
本文介绍了iOS-Face ID生物识别集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的应用程序集成/实现了Face ID(本地身份验证)身份验证,并且一切正常,除了Face ID提示警报"窗口界面之外.

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

它显示一个带有浅灰色背景的圆角正方形,标题为脸ID" .

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

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.

看看这个快照:

这是我的代码:

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

            })
        })
    }

推荐答案

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

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

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

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

他们都运行了相同的代码:

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

}

这里是TouchID和amp;带有所有错误代码的FaceID (快捷键4)

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

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

这篇关于iOS-Face ID生物识别集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆