gpt4 book ai didi

ios - 检查 FaceID 是否正确?

转载 作者:搜寻专家 更新时间:2023-10-30 22:26:45 24 4
gpt4 key购买 nike

Sorry, unavailability of iPhone-X.

在 iPhone-X 推出后,每个人都希望他们的应用程序应该兼容 iOS11 和 touchID,但问题是开发人员测试 touch ID 的成本太高。

我没有 iPhone 来检查我的代码,但我可以在 iOS 模拟器中检查吗?

let context = LAContext()
if ( context.biometryType == .typeFaceID ) {
// Face ID
}
if ( context.biometryType == .typeTouchID) {
// Touch ID
} else {
// Stone Age
}

最佳答案

您也可以在没有设备的情况下进行测试。使用模拟器的 Face ID 验证您的代码,它在 iPhone-X 中的行为也类似。

如果您从 Face ID 启用了 Enrolled 选项,模拟器无法识别人脸,但允许您模拟匹配和不匹配的人脸。

将以下代码添加到您的 View Controller 并尝试使用 Face-ID

import LocalAuthentication

class ViewController: UIViewController {


override func viewDidLoad() {
super.viewDidLoad()
localAuthentication()
}



func localAuthentication() -> Void {

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, *) {
if (laContext.biometryType == LABiometryType.faceID) {
localizedReason = "Unlock using Face ID"
print("FaceId support")
} else if (laContext.biometryType == LABiometryType.touchID) {
localizedReason = "Unlock using Touch ID"
print("TouchId support")
} else {
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")
}
}

})
})
}


}
}


FaceID 身份验证将提示您首次允许对您的应用进行 FaceID 检测。

enter image description here


现在启用 Face ID 注册并运行您的应用程序以测试 Face ID 模拟测试。

这是匹配和非匹配人脸的模拟结果。

人脸匹配结果:

enter image description here


不匹配人脸的结果:

enter image description here

关于ios - 检查 FaceID 是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47181238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com