gpt4 book ai didi

ios - 如何检测指纹传感器不可用的设备

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:34:08 24 4
gpt4 key购买 nike

我在我的 iOS 应用程序中启用了触控 ID。但 iPhone 5 和 5c 指纹传感器不可用。如何以编程方式检测没有指纹传感器的设备。我的应用程序是用 objective-c 编写的。

请帮帮我。谢谢

最佳答案

您应该使用 Touch ID 身份验证所需的 LAContext 框架。

LAErrorTouchIDNotAvailable 显示哪个设备具有该功能。

代码片段:

- (IBAction)shouldAuthenticate:(id)sender {
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
// Authentication here.
} else {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Your device cannot authenticate using TouchID."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];

}
}

或者试试这个以获得 BOOL 返回:

- (BOOL)canAuthenticateByTouchId {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
}
return NO;
}

关于ios - 如何检测指纹传感器不可用的设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42019069/

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