Sam*_*ram 5 ios touch-id swift iphone-x face-id
对不起,iPhone-X不可用.
在推出iPhone-X之后,每个人都希望他们的应用程序应该与iOS11和touchID兼容,但问题是开发人员测试触摸ID太昂贵了.
我没有iPhone来检查我的代码,但我可以在iOS模拟器中检查相同吗?
let context = LAContext()
if ( context.biometryType == .typeFaceID ) {
// Face ID
}
if ( context.biometryType == .typeTouchID) {
// Touch ID
} else {
// Stone Age
}
Run Code Online (Sandbox Code Playgroud)
Kru*_*nal 11
你也可以不用设备测试它.使用模拟器的Face ID来验证您的代码,它在iPhone-X中的行为也类似.
模拟器无法识别面部,但允许您模拟匹配和不匹配的面,如果您已启用Enrolled选项Face ID.
将以下代码添加到视图控制器并尝试使用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")
}
}
})
})
}
}
}
Run Code Online (Sandbox Code Playgroud)
FaceID身份验证将提示您第一次为您的应用程序允许FaceID检测.
现在启用Face ID注册并运行您的应用以测试Face ID模拟测试.
这是匹配和不匹配面的模拟结果.
匹配面的结果:
不匹配面的结果:

| 归档时间: |
|
| 查看次数: |
3676 次 |
| 最近记录: |