Ale*_*eem 4 xcode objective-c ios11 face-id
它有点早,但我打算专门为FaceID添加功能,所以在此之前我需要验证设备支持FaceID与否?需要建议和帮助.提前致谢.
Stu*_* P. 10
我发现你必须先调用canEvaluatePolicy才能正确获取生物测量类型.如果不这样做,那么原始值总是为0.
所以在Swift 3中就是这样,在Xcode 9.0和beta 9.0.1中进行了测试和工作.
class func canAuthenticateByFaceID () -> Bool {
//if iOS 11 doesn't exist then FaceID doesn't either
if #available(iOS 11.0, *) {
let context = LAContext.init()
var error: NSError?
if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error) {
//As of 11.2 typeFaceID is now just faceID
if (context.biometryType == LABiometryType.typeFaceID) {
return true
}
}
}
return false
}
Run Code Online (Sandbox Code Playgroud)
你当然可以写这个,只是为了看它是否是生物识别并将类型与bool一起返回,但这对于大多数人来说应该足够了.
Objective-C版本
- (BOOL) isFaceIdSupported{
if (@available(iOS 11.0, *)) {
LAContext *context = [[LAContext alloc] init];
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]){
return ( context.biometryType == LABiometryTypeFaceID);
}
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
感谢 Ashley Mills,我创建了一个函数来检测设备中的 FaceID。
- (BOOL)canAuthenticateByFaceID {
LAContext *context = [[LAContext alloc] init];
if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error) {
if (context.biometryType == LABiometryTypeFaceID && @available(iOS 11.0, *)) {
return YES;
} else {
return NO;
}
}
}
Run Code Online (Sandbox Code Playgroud)
希望这会帮助其他人。快乐编码!!
最后我写了我自己的库来检测 FaceID在这里你找到