canEvaluatePolicy
来正确设置biometryType
。
例如:
func isFaceIdSupported() -> Bool {
if #available(iOS 11.0, *){
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
return context.biometryType == LABiometryType.typeFaceID
}
}
return false
}
我这里也遇到了同样的问题,通过以下代码进行了修复。但是仅适用于Xcode 9.1 Beta(在模拟器中使用iOS 11.1 beta)。
if (laContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: nil)) {
if #available(iOS 11.0, *) {
if (laContext.biometryType == LABiometryType.faceID) {
print("FaceId support")
} else if (laContext.biometryType == LABiometryType.touchID) {
print("TouchId support")
} else {
print("No Biometric support")
}
} else {
// Fallback on earlier versions
}
}
如果您使用@Ermish的代码,如果设备上没有注册面部信息,则isFaceIdSupported()函数将返回假。 根据我最近在iOS SDK 11.1上的测试,只需调用laContext.canEvaluatePolicy函数并不关心结果,然后检查laContext.biometryType的内容即可。
如果没有注册面部信息,canEvaluatePolicy函数将失败,但是设备支持Face ID。
.canEvaluatePolicy(parameters)
在laContext
的实例上设置.biometryType
。我犯了一个错误,每次都使用新的实例LAContext()。 - Rickard Elimää NSError error;
bool success = context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out error);
if (context.BiometryType == LABiometryType.TouchId)
{
//Do Something
}