我在我的iOS应用程序中启用了touch id。但是iPhone 5和5c指纹传感器是不可用的。如何以编程方式检测没有指纹传感器的设备。我的应用程序是用objective编写的。
请帮帮我。谢谢
发布于 2017-02-03 07:49:14
您应该使用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;
}发布于 2017-09-12 06:53:36
func checkIfTouchIDEnabled() {
var error:NSError?
// 2. Check if the device has a fingerprint sensor
// If not, show the user an alert view and bail out!
guard authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
if let error = error as NSError? {
if error.code == LAError.Code.touchIDNotAvailable.rawValue { /* Device does not support touch id*/
print("Finger print sensors are not present in this device")
} else if error.code == LAError.Code.touchIDNotEnrolled.rawValue {
print("Finger print sensors are present in this device but no TouchID has been enrolled yet")
} else {
// Add more checks ...
}
}
return
}
}https://stackoverflow.com/questions/42019069
复制相似问题