IOS指纹实现

sil*_*eep 5 fingerprint ios ios7 xcode5

由于Apple发布了在iOS 7中具有FingerPrint扫描功能的Xcode 5,我们可以在我们的应用程序中实现这一点吗?如果是,我们使用哪个SDK进行实施.

请提供示例代码或指定我们使用的SDK.

sil*_*eep 1

它可以通过使用LAContext本地身份验证框架)来实现,该框架可用于评估安全策略。它使用 Touch ID 传感器检查进行身份验证的人是否是设备所有者。未来可能还会有其他安全策略。

这是相同的代码片段:

-(void)handlerForFingerTouch{
   LAContext *context = [[LAContext alloc] init];

   NSError *error = nil;
   if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
       [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
               localizedReason:@"Are you the device owner?"
                         reply:^(BOOL success, NSError *error) {

           if (error) {
               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                               message:@"There was a problem verifying your identity."
                                                              delegate:nil
                                                     cancelButtonTitle:@"Ok"
                                                     otherButtonTitles:nil];
               [alert show];
               return;
           }

           if (success) {
               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                                               message:@"You are the device owner!"
                                                              delegate:nil
                                                     cancelButtonTitle:@"Ok"
                                                     otherButtonTitles:nil];
               [alert show];

           } else {
               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                               message:@"You are not the device owner."
                                                              delegate:nil
                                                     cancelButtonTitle:@"Ok"
                                                     otherButtonTitles:nil];
               [alert show];
           }

       }];

   } else {

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

   }
}
Run Code Online (Sandbox Code Playgroud)