IOS開發-指紋識別

蘋果系統自帶指紋識別功能,只需要調用方法就可以實現指紋識別的功能

代碼:

<span style="font-size:14px;"> if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
            NSLog(@"不支持");
            return;
        }
        LAContext *ctx = [[LAContext alloc] init];
        // 判斷設備是否支持指紋識別
        if ([ctx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL]) {
            NSLog(@"支持");
            // 異步
            // 提示:指紋識別只是判斷當前用戶是否是手機的主人。
            [ctx evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"指紋登錄" reply:^(BOOL success, NSError *error) {
                if (success) {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"指紋認證成功" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil];
                    [alert show];
                }else if(error){
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"指紋認證失敗" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil];
                    [alert show];
                }
            }];
        } else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"沒有開啓TOUCHID設備" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil];
            [alert show];
        }</span>

只需要在方法中加入上面的代碼,就可以直接調用,實現指紋認證

#import "LocalAuthentication/LAContext.h"

頭文件導入不能忘了


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章