【发布时间】:2019-01-04 10:49:15
【问题描述】:
我想获取设备中当前使用的锁类型的字符串,无论是 FaceID、touchID 还是 PassCode。以下是我的代码:-
func getBiometricType() -> String {
var biometricType: Global.BiometricType {
let context = LAContext()
var error: NSError?
guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else { return .none }
if #available(iOS 11.0, *) {
switch context.biometryType {
case .touchID:
return .touchID
case .faceID:
return .faceID
case .none:
return .none
}
} else {
guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else { return .none }
return context.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) ?
.touchID : .PIN
}
}
return biometricType.rawValue
}
但是这个 canEvaluatePolicy 只检查设备是否支持生物识别。即使 FaceID 尚未设置但启用了密码,它也不会提供有关密码的信息。因为我需要显示启用的类型是“密码”。有什么方法可以实现吗?
【问题讨论】:
标签: ios swift biometrics face-id passcode