Ios7 iOS8触摸ID&;密码

Ios7 iOS8触摸ID&;密码,ios7,ios8,keychain,biometrics,touch-id,Ios7,Ios8,Keychain,Biometrics,Touch Id,为了安全起见,我在iOS 8中使用此代码,并使用触摸ID - (IBAction)authenticateButtonTapped{ LAContext *myContext = [[LAContext alloc] init]; NSError *authError = nil; NSString *myLocalizedReasonString = @"Authenticate using your finger\r Scan Your Finger Now

为了安全起见,我在iOS 8中使用此代码,并使用触摸ID

- (IBAction)authenticateButtonTapped{





    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;
    NSString *myLocalizedReasonString = @"Authenticate using your finger\r Scan Your 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\"");

                                            [self copyMatchingAsync];
                                            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");
        [self showMessage:@"Can not evaluate TouchID" withTitle:@"Error"];

    }







}
在使用密码系统之后,我从苹果的例子中复制了这段代码

- (void)copyMatchingAsync
{
    NSDictionary *query = @{
                            (__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
                            (__bridge id)kSecAttrService: @"SampleService",
                            (__bridge id)kSecReturnData: @YES,
                            (__bridge id)kSecUseOperationPrompt: NSLocalizedString(@"AUTHENTICATE_TO_ACCESS_SERVICE_PASSWORD", nil)
                            };

    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        CFTypeRef dataTypeRef = NULL;
        NSString *msg;

        OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)(query), &dataTypeRef);
        if (status == errSecSuccess)
        {
            NSData *resultData = ( __bridge_transfer NSData *)dataTypeRef;
            NSString * result = [[NSString alloc] initWithData:resultData encoding:NSUTF8StringEncoding];

            msg = [NSString stringWithFormat:NSLocalizedString(@"RESULT", nil), result];
        } else {

        }

    });
}

-(void) showMessage:(NSString*)message withTitle:(NSString *)title
{

    UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:title
                                  message:message
                                  preferredStyle:UIAlertControllerStyleAlert];


    UIAlertAction* cancel = [UIAlertAction
                             actionWithTitle:@"OK"
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action)
                             {
                                 [alert dismissViewControllerAnimated:YES completion:nil];

                             }];

    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:nil];
}
它可以快速有效地提取指纹,但密码系统无法显示,无法工作。我收到了“ERROR\u ITEM\u NOT\u FOUND”=“ERROR ITEM NOT FOUND”

这个苹果链接


但我不能很好地理解

很抱歉告诉你,但你不能这么做。 您将访问控制与钥匙链访问混合在一起,您无权访问用户密码

如果使用相同的属性(“查询”的内容)添加了具有SecItemAdd的资源,则可以使用SecItemCopyMatching

“ERROR\u ITEM\u NOT\u FOUND”=“ERROR ITEM NOT FOUND”在keychain中不显示任何项

我还看到了苹果的示例代码“KeychainTouchID”,如您上面所说

iOS8的新功能使开发者可以使用iPhone用户的密码和触摸ID进行身份验证

您必须先“添加项”,然后调用“查询项”

如果你想要更方便的解决方案,也许你可以使用

它是一个库,可以方便地将触摸ID和密码集成到iOS应用程序中,甚至支持iOS7和不支持触摸ID的设备

你只需要几行代码就可以得到你想要的

if ([SmileAuthenticator hasPassword]) {
        [SmileAuthenticator sharedInstance].securityType = INPUT_TOUCHID;
        [[SmileAuthenticator sharedInstance] presentAuthViewController];
    }

如果效果很好,你有什么要求?您希望密码系统易于测试是什么意思?密码系统不工作且不显示是否有任何错误打印到NSLog?我收到“未找到项”,“未找到项错误”=“未找到项错误”;