Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何检测设备中是否配置了触摸ID_Ios_Objective C_Xcode6.3_Ios8.3_Touch Id - Fatal编程技术网

Ios 如何检测设备中是否配置了触摸ID

Ios 如何检测设备中是否配置了触摸ID,ios,objective-c,xcode6.3,ios8.3,touch-id,Ios,Objective C,Xcode6.3,Ios8.3,Touch Id,我使用下面的代码来检测设备中的触摸ID可用性,它工作正常 - (BOOL)canAuthenticateByTouchId { if ([LAContext class]) { return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]; } return NO; } - (IBActio

我使用下面的代码来检测设备中的触摸ID可用性,它工作正常

- (BOOL)canAuthenticateByTouchId
{
    if ([LAContext class])
    {
        return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
    }

    return NO;
}
- (IBAction)touchIDAvailability
{
    if([self canAuthenticateByTouchId])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congrats"
                                                        message:@"Your device have TouchID"
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
        [alert show];
    }
    else
    {

        str = @"TouchID is not available in your device";
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops"
                                                        message:str
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
        [alert show];

    }
}
检测到触摸ID可用性后,我想查找触摸ID是否已配置

NSString *str;

if (LAErrorTouchIDNotEnrolled)
{
    str = @"Please configure your TouchID in Settings > Touch ID & Passcode";
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops"
                                                            message:str
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
[alert show];

我配置了触摸ID,但它仍然进入了LaErrorTouchIDNoten循环。任何人都可以告诉我。

您可以检查用户是否配置了以下功能

[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                          localizedReason:myLocalizedReasonString
                                    reply:^(BOOL succes, NSError *error) {
}
以下是触摸ID的完整代码

LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
myContext.localizedFallbackTitle=@"Login with Password";//optional for hiding enter password button
NSString *myLocalizedReasonString = @"For touch ID Users Ignore this pop-up and proceed to login with you finger now";

        if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {

            [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                      localizedReason:myLocalizedReasonString
                                reply:^(BOOL succes, NSError *error) {
                                    if (succes) {
                                       [self showMessage:@"Authentication is successful" withTitle:@"Success"];
                                 NSLog(@"User authenticated");                                        }
                                    } else {

                                        switch (error.code) {
                                            case LAErrorAuthenticationFailed:
                                                [self showMessage:@"Authentication is failed" withTitle:@"Error"];
                                                NSLog(@"Authentication Failed");
                                                break;

                                            case LAErrorUserCancel:
                                               [self showMessage:@"You clicked on Cancel" withTitle:@"Error"];
                                                NSLog(@"User pressed Cancel button");
                                                break;

                                            case LAErrorUserFallback:
                                                [self showMessage:@"You clicked on \"Enter Password\"" withTitle:@"Error"];
                                                NSLog(@"User pressed \"Enter Password\"");
                                                break;

                                            default:
                                                [self showMessage:@"Touch ID is not configured" withTitle:@"Error"];
                                                NSLog(@"Touch ID is not configured");
                                                break;
                                        }

                                        NSLog(@"Authentication Fails");
                                    }
                                }];
        } else {
    NSLog(@"Can not evaluate Touch ID");

    NSString *str = @"TouchID is not available in your device";
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops"
                                                    message:str
                                                   delegate:nil
                                          cancelButtonTitle:@"Ok"
                                          otherButtonTitles:nil];
    [alert show];
        }
    }


-(void) showMessage:(NSString*)message withTitle:(NSString *)title
{
    [[[UIAlertView alloc] initWithTitle:@"AppName" message:message delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil] show];
}

希望对你有帮助

我会检查这段代码并让你们知道Vidhyanaad谢谢。我用iPhone 6 plus测试了上述代码,我没有在设备中添加任何指纹。它无法检测指纹是否存在,它显示“TouchID在您的设备中不可用”。如果我在触摸id设置中添加指纹,它可以正常工作。只设置指纹后,它可以正常工作。使用上述代码将引发不同的错误。如果它符合您的要求,请接受它作为答案。