iOS 第三方读取指纹

来源:互联网 发布:怎么修改电脑的端口 编辑:程序博客网 时间:2024/05/19 20:00

  第三方读取指纹必须是在ios8以上

首先导入TouchId的必须库 #import <LocalAuthentication/LocalAuthentication.h> 这个库必须要Xcode6并且连接的是真机,才不会提示找不到的错误,即使不是iPhone5s都行. 如果是模拟器会提示找不到这个库

然后在某个触发的事件内写上如下代码

 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];    LAContext *myContext = [[LAContext alloc] init];    NSError *authError = nil;    NSString *myLocalizedReasonString = @"Restricted Area!";    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {        [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics                  localizedReason:myLocalizedReasonString                            reply:^(BOOL success, NSError *error) {                                if (success) {                                    // User authenticated successfully, take appropriate action                                    alert.title = @"Success";                                    alert.message = @"You have access to private content!";                                    [alert show];                                } else {                                    // User did not authenticate successfully, look at error and take appropriate action                                    alert.title = @"Fail";                                    switch (error.code) {                                        case LAErrorUserCancel:                                            alert.message = @"Authentication Cancelled";                                            break;                                        case LAErrorAuthenticationFailed:                                            alert.message = @"Authentication Failed";                                            break;                                        case LAErrorPasscodeNotSet:                                            alert.message = @"Passcode is not set";                                            break;                                        case LAErrorSystemCancel:                                            alert.message = @"System cancelled authentication";                                            break;                                        case LAErrorUserFallback:                                            alert.message = @"You chosed to try password";                                            break;                                        default:                                            alert.message = @"You cannot access to private content!";                                            break;                                    }                                    [alert show];                                }                            }];    } else {        // Could not evaluate policy; look at authError and present an appropriate message to user        alert.title = @"Warning";        if(authError.code == LAErrorTouchIDNotEnrolled) {            alert.message = @"You do not have any fingerprints enrolled!";        }else if(authError.code == LAErrorTouchIDNotAvailable) {            alert.message = @"Your device does not support TouchID authentication!";        }else if(authError.code == LAErrorPasscodeNotSet){            alert.message = @"Your passcode has not been set";        }        [alert show];    }

0 0
原创粉丝点击