IOS8获取指纹数据

IOS8 get fingerprint data

在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];

  }
}

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

不,您不能读取或保存指纹数据。甚至 Apple 也不收集这些数据。您只能使用 Touch ID 传感器使用用户已保存在系统偏好设置中的指纹来解锁您的应用程序。

您可以这样验证:

 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)
    }
}