4
A
回答
6
试试这个:
- (BOOL)canAuthenticateByTouchId {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
}
return NO;
}
或类似@rckoenes建议:
- (BOOL)canAuthenticateByTouchId {
if ([LAContext class]) {
return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
}
return NO;
}
UPDATE
我忘了,看看这个:How can we programmatically detect which iOS version is device running on?定义SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO
5
你应该考虑触摸身份验证所需的框架。
而参数LAErrorTouchIDNotAvailable
会显示是设计支持这个功能。
代码片段:
- (IBAction)authenticateButtonTapped:(id)sender {
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
// Authenticate User
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Your device cannot authenticate using TouchID."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
}
尼斯教程来学习这个功能here。
0
此功能将有助于利用 -
-(BOOL)doesThisDeviceSupportTouchIdForLocalAuthentication{
//Checking for 64 bit (armv7s) architecture before including the LAContext as it would give error otherwise.
#if TARGET_CPU_ARM64
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]){
return YES;
}
return NO;
#endif
return NO;
}
3
您可以检查使用CanEvaluatePolicy
错误。如果错误代码是-6,则表示该设备上没有物理Touch ID。你可以从错误描述中知道,它说
生物特征不适用于此设备。
下面是如果你使用C#Xamarin代码:
var context = new LAContext();
NSError AuthError;
if (!context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError))
{
if (AuthError != null && AuthError.Code == -6)
{
var alert = new UIAlertView ("Error", "TouchID not available", null, "BOOO!", null);
alert.Show();
}
}
0
目标C
@import LocalAuthentication;
// Get the local authentication context:
LAContext *context = [[LAContext alloc] init];
// Test if fingerprint authentication is available on the device and a fingerprint has been enrolled.
if ([context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil])
{
NSLog(@"Fingerprint authentication available.");
}
+0
欢迎来到Stack Overflow! [如何回答](http://stackoverflow.com/help/how-to-answer)可以帮助你写出将被接受和upvoted的答案。在你的情况下,代码应该放在代码块中。 – zhon 2016-09-04 19:45:15
相关问题
- 1. 如何检测JavaScript中的设备触摸支持?
- 2. iphone/ipads或任何可触摸设备的highchart触摸事件支持
- 3. Android设备如果不支持多点触摸,有什么办法可以检测多点触摸吗?
- 4. 使用触摸ID保护设备的3D触摸动作
- 5. 支持jQuery和触摸设备的水平滑动滑块?
- 6. 触摸屏设备支持onmousedown和onmouseup吗?
- 7. 在支持的设备上的Android多点触摸
- 8. Jquery hoverIntent/hover函数支持触摸设备
- 9. 查找设备支持的触摸次数
- 10. 检查iOS9设备是否支持3D触摸并启用
- 11. jquery触摸设备
- 12. 在苹果设备上触摸事件
- 13. 触摸屏设备的“拖动”效果
- 14. 如何使在支持3D触摸(力触摸)
- 15. 我如何找到我的android设备支持的最大触摸次数
- 16. 触摸设备的HTML API?
- 17. 触摸屏设备的pygtk
- 18. 触摸屏测试设备
- 19. 延迟对触摸设备
- 20. 悬停触摸设备
- 21. 翻转触摸设备
- 22. EventListener的触摸设备的
- 23. Android设备为触摸板
- 24. 检测触摸设备
- 25. HTML和触摸设备
- 26. 如何获取nook简单触摸的设备ID?
- 27. 如何在CSS中只触摸非触摸设备?
- 28. 用触摸设备触发mousewheel事件
- 29. 虚拟触摸屏设备未报告对X或Y轴的支持?
- 30. 是否Windows应用商店的应用或HTML5拖放支持触摸设备?
更好地利用'如果([LAContext类]){'它代替检查的系统版本。既然你有兴趣,如果类是可用的,而不是真的在系统版本。您应该避免检查系统版本,请检查基础版本或仅在类或方法可用时。 – rckoenes 2014-11-25 10:21:04
你说得对,我更新了答案。谢谢。 – Mateusz 2014-11-25 10:42:12
只需添加:这不会检测设备是否具有TouchID功能。它仅检查设备设置中是否启用了TouchID。下面的Siti Kamaludin的答案更好。 – GeneCode 2017-07-05 03:20:21