IOS8获取指纹数据

时间:2015-04-07 13:22:21

标签: ios objective-c swift fingerprint

在IOS8中,我可以获取指纹数据并将其保存或在其他地方使用,

此代码自动化

- (void)authenicateButtonTapped:(id)sender {
 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];

  }
}

但我不会对用户进行身份验证,我不会获取指纹数据并将此数据发送到服务器端,然后服务器端将检查该指纹数据。

2 个答案:

答案 0 :(得分:5)

不,您无法读取或保存指纹数据。甚至Apple也不会收集这些数据。您只能使用Touch ID传感器使用用户已在系统首选项中保存的指纹来解锁您的应用。

答案 1 :(得分:2)

您可以通过以下方式进行身份验证:

 func authenticateUser() {
    let context = LAContext()
    var error: NSError?

    if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
        let reason = "Identify yourself!"

        context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
            [unowned self] success, authenticationError in

            DispatchQueue.main.async {
                if success {
                    let ac = UIAlertController(title: "Login with TouchID", message: "Sucessfully Login", preferredStyle: .alert)
                    ac.addAction(UIAlertAction(title: "OK", style: .default))
                    self.present(ac, animated: true)
                } else {
                    let ac = UIAlertController(title: "Authentication failed", message: "Sorry!", preferredStyle: .alert)
                    ac.addAction(UIAlertAction(title: "OK", style: .default))
                    self.present(ac, animated: true)
                }
            }
        }
    } else {
        let ac = UIAlertController(title: "Touch ID not available", message: "Your device is not configured for Touch ID.", preferredStyle: .alert)
        ac.addAction(UIAlertAction(title: "OK", style: .default))
        present(ac, animated: true)
    }
}

enter image description here